diff --git a/src/Uno.UI.Tests/Windows_UI_XAML_Controls/TextBoxTests/Given_TextBox.cs b/src/Uno.UI.Tests/Windows_UI_XAML_Controls/TextBoxTests/Given_TextBox.cs index dc7e7f58df50..3a92003d4c1b 100644 --- a/src/Uno.UI.Tests/Windows_UI_XAML_Controls/TextBoxTests/Given_TextBox.cs +++ b/src/Uno.UI.Tests/Windows_UI_XAML_Controls/TextBoxTests/Given_TextBox.cs @@ -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(() => 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] diff --git a/src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs b/src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs index a0cbf28a2ee7..d752248fcd8f 100644 --- a/src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs +++ b/src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs @@ -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);