Skip to content

Commit

Permalink
Merge pull request #11113 from Youssef1313/textbox-text-null
Browse files Browse the repository at this point in the history
fix(TextBox): Setting `TextBox.Text` to `null` should only throw in UWP
  • Loading branch information
jeromelaban authored Jan 31, 2023
2 parents 0ed5416 + 507d35c commit 46b2708
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,19 @@ public void When_Setting_Text_Null()
textBox.Text = "Rhubarb";
Assert.AreEqual("Rhubarb", textBox.Text);
Assert.AreEqual(1, callbackCount);


#if !HAS_UNO_WINUI
// Setting TextBox.Text to null throws an exception in UWP but not WinUI.
Assert.ThrowsException<ArgumentNullException>(() => textBox.Text = null);
#endif

Assert.AreEqual("Rhubarb", textBox.Text);
Assert.AreEqual(1, callbackCount);

#if HAS_UNO_WINUI
textBox.Text = null;
Assert.AreEqual("", textBox.Text);
#endif
}

[TestMethod]
Expand Down
4 changes: 4 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,11 @@ public string Text
{
if (value == null)
{
#if HAS_UNO_WINUI
value = string.Empty;
#else
throw new ArgumentNullException();
#endif
}

this.SetValue(TextProperty, value);
Expand Down

0 comments on commit 46b2708

Please sign in to comment.