Skip to content

Commit 26cd3f9

Browse files
Merge pull request #3960 from RosarioPulella/unsetValue-to-null
Fix Incorrect usages of UnsetValue
2 parents 2b124ff + 89fe685 commit 26cd3f9

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/EnumValuesExtension/AnimalToColorConverter.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System;
66
using Microsoft.Toolkit.Uwp.SampleApp.Enums;
77
using Windows.UI;
8+
using Windows.UI.Xaml;
89
using Windows.UI.Xaml.Data;
910

1011
namespace Microsoft.Toolkit.Uwp.SampleApp.Converters
@@ -21,7 +22,7 @@ public object Convert(object value, Type targetType, object parameter, string la
2122
Animal.Llama => Colors.Beige,
2223
Animal.Parrot => Colors.YellowGreen,
2324
Animal.Squirrel => Colors.SaddleBrown,
24-
_ => throw new ArgumentException("Invalid value", nameof(value))
25+
_ => DependencyProperty.UnsetValue
2526
};
2627
}
2728

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/EnumValuesExtension/EnumValuesExtensionCode.bind

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public sealed class AnimalToColorConverter : IValueConverter
2020
Animal.Bunny => Colors.Green,
2121
Animal.Parrot => Colors.YellowGreen,
2222
Animal.Squirrel => Colors.SaddleBrown,
23-
_ => throw new ArgumentException("Invalid value", nameof(value))
23+
_ => DependencyProperty.UnsetValue
2424
};
2525
}
2626

Microsoft.Toolkit.Uwp.UI/Converters/TaskResultConverter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.Threading.Tasks;
7+
using Windows.UI.Xaml;
78
using Windows.UI.Xaml.Data;
89

910
namespace Microsoft.Toolkit.Uwp.UI.Converters
@@ -26,7 +27,7 @@ public object Convert(object value, Type targetType, object parameter, string la
2627
return task.GetResultOrDefault();
2728
}
2829

29-
return null;
30+
return DependencyProperty.UnsetValue;
3031
}
3132

3233
/// <inheritdoc/>

Microsoft.Toolkit.Uwp.UI/Extensions/UIElementExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static class UIElementExtensions
2020
"ClipToBounds",
2121
typeof(bool),
2222
typeof(UIElementExtensions),
23-
new PropertyMetadata(DependencyProperty.UnsetValue, OnClipToBoundsPropertyChanged));
23+
new PropertyMetadata(null, OnClipToBoundsPropertyChanged));
2424

2525
/// <summary>
2626
/// Gets the value of <see cref="ClipToBoundsProperty"/>

UnitTests/UnitTests.UWP/Converters/Test_TaskResultConverter.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.Toolkit.Uwp.UI.Converters;
99
using Microsoft.VisualStudio.TestTools.UnitTesting;
1010
using Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer;
11+
using Windows.UI.Xaml;
1112

1213
namespace UnitTests.Converters
1314
{
@@ -70,12 +71,19 @@ public void Test_TaskResultConverter_Instance_String()
7071

7172
[TestCategory("Converters")]
7273
[UITestMethod]
73-
public void Test_TaskResultConverter_Instance_Null()
74+
public void Test_TaskResultConverter_Instance_UnsetValue()
7475
{
7576
var converter = new TaskResultConverter();
7677

77-
Assert.AreEqual(null, converter.Convert(null, null, null, null));
78-
Assert.AreEqual(null, converter.Convert("Hello world", null, null, null));
78+
Assert.AreEqual(DependencyProperty.UnsetValue, converter.Convert(null, null, null, null));
79+
Assert.AreEqual(DependencyProperty.UnsetValue, converter.Convert("Hello world", null, null, null));
80+
}
81+
82+
[TestCategory("Converters")]
83+
[UITestMethod]
84+
public void Test_TaskResultConverter_Instance_Null()
85+
{
86+
var converter = new TaskResultConverter();
7987

8088
var cts = new CancellationTokenSource();
8189

0 commit comments

Comments
 (0)