Skip to content
This repository was archived by the owner on Feb 25, 2026. It is now read-only.
20 changes: 14 additions & 6 deletions Microsoft.Toolkit.Uwp.UI/Triggers/IsEqualStateTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ public object To

internal static bool AreValuesEqual(object value1, object value2, bool convertType)
{
if (value1 == value2)
if (object.Equals(value1, value2))
{
return true;
}

if (value1 != null && value2 != null && convertType)
// If they are the same type but fail with Equals check, don't bother with conversion.
if (value1 != null && value2 != null && value1.GetType() != value2.GetType() && convertType)
Comment thread
huoyaoyuan marked this conversation as resolved.
Outdated
{
// Try the conversion in both ways:
return ConvertTypeEquals(value1, value2) || ConvertTypeEquals(value2, value1);
Expand All @@ -92,14 +93,21 @@ private static bool ConvertTypeEquals(object value1, object value2)

private static object ConvertToEnum(Type enumType, object value)
{
try
// value cannot be the same type of enum now
if (value is string str)
{
return Enum.IsDefined(enumType, value) ? Enum.ToObject(enumType, value) : null;
return Enum.TryParse(enumType, str, out var e) ? e : null;
}
catch

if (value is int || value is uint
|| value is byte || value is sbyte
|| value is long || value is ulong
|| value is short || value is ushort)
Comment thread
huoyaoyuan marked this conversation as resolved.
Outdated
{
return null;
return Enum.ToObject(enumType, value);
}

return null;
}
}
}