-
-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CompareStateTrigger, EqualsStateTrigger and NotEqualStateTrigger can return unexpected results #37
Comments
Only types that implement IComparable are supported for this Compare trigger. If these are reference objects, I would actually expect it to be a by-reference comparison. So IMHO the current behavior is correct. |
I don't know if this is the correct issue, but i'm facing a very strange behavior with the EqualStateTrigger. It's simply does not trigger. When i debug the trigger something odd happens: As you can see, both values are 0 and both values are int, but the comparison is false. Therefore the trigger never fires..... |
@SvenLauterbach If you continue stepping into this method, where does it go wrong? |
@dotMorten it goes wrong in the very first line, because the first if statement should be entered, but for some reason "value1 == value2" returns "false" (see my screenshot). Instead the execution goes into the second if statement (both values are not null) and then it goes straight to the "return false" at the bottom of the method because the third if statement is also false (both values have the same type as you can see in my screenshot). So, both values are 0, both values are int, so i think it should just enter the first if statement and return true - but it doesn't. |
using .Equal() does the trick..... A good explanation why : http://blogs.msdn.com/b/csharpfaq/archive/2004/03/29/when-should-i-use-and-when-should-i-use-equals.aspx |
The strings doesn't compare through ==, too. When they are considered as objects, they should be compared through Equals. |
CompareStateTrigger, EqualsStateTrigger and NotEqualStateTrigger, since it uses EqualsStateTrigger internally, can return unexpected results because they use == for comparison rather than object.Equals(…). The result is a reference comparison when that was probably not intended.
Fixes:
Change comparisons from using == to object.Equals(…).
CompareStateTrigger.cs
EqualsStateTrigger.cs
To Reproduce:
The provided example shows the issue with the EqualsStateTrigger, using boolean values. CompareStateTrigger seems to do better in this particular case because it uses IComparable when possible. However, CompareStateTrigger has given me similar issues using enums. I can provide an example of the latter as proof if necessary.
MainPage.xaml
The text was updated successfully, but these errors were encountered: