Describe the bug
When CheckChangedCommand called, the
CheckChangedCommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=IsChecked}" is the old value.
To Reproduce
<controls:ToggleSwitch IsChecked="{Binding xxx}"
CheckChangedCommand="..."
CheckChangedCommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=IsChecked}" />
void ExecuteCheckChanged(bool? isChecked) {
// isChecked is the old value, in other words it's false if checked and true if unchecked
// But CheckedCommand and UnCheckedCommand works as expected
}
Expected behavior
it's true if checked and false if unchecked.
Environment(please complete the following information):
Pretty sure that this isn't a MahApps specific problem, but rather with order of execution.
If im not mistaken the binding is changed during the xaml parsing process, which fires when the element get's changed, but the command fires off before that, resulting in it sending of the old value before the new one was set.
Sorry I don't understand what the meaning of the binding is changed during the xaml parsing process.
Who's changing the binding ? I only binding once in xaml CheckChangedCommand="{Binding xxx}".
Sorry, i was somewat wrong, just noticed that the CheckedChangedCommand is MahApps specific..
The relative source which you bind to needs to be updated , in this case if the value is true or false. When you checkbox is checked it changes it's state which then tirgger's all events, it also triggers the xaml parsing process which parses the data and updates the element as needed, if im not mistaking then thats also where the relative source gets updated to watever the new value is.
The CheckedChangedCommand get's execute right after the value changes, in the same event, i have a feeling that this happens before the xaml parser went over the values and changed it resulting in the old value being send off, each and everytime.
If u were to do the same, but used the CheckedCommandand CheckedCommandParameter, u would notice that the return value is correct
One way of solving it as well is to do away with the IsChecked binding, since the button icChecked state is then no longer reliant on a property, and doesnt need to wait for the INotifyPropertyChanged and then update everything, it seems that the RelativeSourceupdates right away, or bind the OnCheckChangedParameter to the IsChecked property, which is updated before the command fires .
You're right, thanks.
If this has been resolved, feel free to close the issue :thumbsup:
Most helpful comment
If this has been resolved, feel free to close the issue :thumbsup: