WPF: Once I set a property in code, it ignores XAML binding forever more... how do I prevent that?
Posted
by Timothy Khouri
on Stack Overflow
See other posts from Stack Overflow
or by Timothy Khouri
Published on 2010-04-04T01:11:22Z
Indexed on
2010/04/04
1:13 UTC
Read the original article
Hit count: 375
I have a button that has a datatrigger that is used to disable the button if a certain property is not set to true:
<Button Name="ExtendButton" Click="ExtendButton_Click" Margin="0,0,0,8">
<Button.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding IsConnected}" Value="False">
<Setter Property="Button.IsEnabled" Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
That's some very simple binding, and it works perfectly. I can set "IsConnected" true and false and true and false and true and false, and I love to see my button just auto-magically become disabled, then enabled, etc. etc.
However, in my Button_Click event... I want to:
- Disable the button (by using ExtendButton.IsEnabled = false;)
- Run some asynchronous code (that hits a server... takes about 1 second).
- Re-enable the button (by using ExtendButton.IsEnabled = true;)
The problem is, the very instant that I manually set IsEnabled to either true or false... my XAML binding will never fire again. This makes me very sad :(
I wish that IsEnabled was tri-state... and that true meant true, false meant false and null meant inherit. But that is not the case, so what do I do?
© Stack Overflow or respective owner