Home > DeveloperSection > Forums > Style triggers produce no effect
Andrew Deniel
Andrew Deniel

Total Post:29

Posted on    July-15-2013 8:36 AM


 0 Reply(s)
 869  View(s)
Rate this:
Hi developers!

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">
           <Trigger Property="IsChecked" Value="True">
              <Setter Property="Header" Value="Metric"/>
           <Trigger Property="IsChecked" Value="False">
              <Setter Property="Header" Value="Imperial"/>

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>


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"/>

No effect.

Help... please...

Thanks in Advance

Don't want to miss updates? Please click the below button!

Follow MindStick