From da0d99e71dbf3aee5d014c1121e0bc7969261bb0 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Tue, 31 Jan 2023 12:27:57 +0200 Subject: [PATCH 1/2] fix(TextBox): Setting `TextBox.Text` to `null` should only throw in UWP --- src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs | 4 ++++ 1 file changed, 4 insertions(+) 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); From 507d35cfab0049587086f446d27e552afc84fc46 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Tue, 31 Jan 2023 13:30:55 +0200 Subject: [PATCH 2/2] chore: Update test --- .../TextBoxTests/Given_TextBox.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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]