Every time I think I finally get WPF/XAML
something unintuitive like this come up (rant over)...
I want to implement a "poor's man" toggle button for a menu item. Essentially, when it's checked it should say "Metric" and when it's unchecked - "Imperial". I thought it should be fairly straightforward with XAML
, but I can't get it to work.
Here's what I tried:
<MenuItem IsCheckable="True" IsChecked="True">
<Style>
<Style.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Header" Value="Metric"/>
</Trigger>
<Trigger Property="IsChecked" Value="False">
<Setter Property="Header" Value="Imperial"/>
</Trigger>
</Style.Triggers>
</Style>
</MenuItem>
It gives me an error "The member 'IsChecked' is not recognized or is not accssible" (same for Header).
The error goes away when I do <Style
TargetType="{x:Type MenuItem}">
, but it doesn't do anything.
I tried directly without the <Style>
<MenuItem.Triggers>
<Trigger...>
</MenuItem.Triggers>
First, it gave me the same error as above, but when I changed the property to Property="MenuItem.IsChecked"
it started screaming that only EventTriggers are allowed.
I also tried with a DataTrigger
(granted, I still don't fully understand the differences between the triggers):
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type MenuItem}}, Path=IsChecked}" Value="True">
<Setter Property="Header" Value="Metric"/>
</DataTrigger>
No effect.
Help... please...
Thanks in Advance
Can you answer this question?
Answer
0 Answers