I work in Windows Presentation Foundation and I need to bind two buttons together. The first button is a classic button, the second is a toggle button. When the user presses the toggle button it becomes "ON" and in this very moment I need to disable开发者_如何学C the classic button. When the user presses the toggle button again and it becomes "OFF", the classic button should become "enabled". Is there any way to do this without a classic binding with converter. I mean triggers or something like that.
You can do it with triggers, but it'd be much more concise with a converter. A triggers version would be something like this:
<Button Content="One">
<Button.Style>
<Style TargetType="Button">
<Style.Triggers>
<DataTrigger Binding="{Binding IsChecked, ElementName=tb}" Value="True">
<Setter Property="IsEnabled" Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
<ToggleButton x:Name="tb">Two</ToggleButton>
With a suitable converter declared as a resource it'd be more like this:
<Button Content="One" IsEnabled="{Binding IsChecked, ElementName=tb, Converter={StaticResource BooleanInverterConverter}}" />
<ToggleButton x:Name="tb">Two</ToggleButton>
精彩评论