wpf - Style triggers produce no effect -


every time think get wpf/xaml unintuitive come (rant over)...

i want implement "poor's man" toggle button menu item. essentially, when it's checked should "metric" , when it's unchecked - "imperial". thought should straightforward xaml, can't work.

here's 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 error "the member 'ischecked' not recognized or not accssible" (same header).

the error goes away when <style targettype="{x:type menuitem}">, doesn't anything.

i tried directly without <style>

<menuitem.triggers>    <trigger...> </menuitem.triggers> 

first, gave me same error above, when changed property property="menuitem.ischecked" started screaming eventtriggers allowed.

i tried datatrigger (granted, still don't understand differences between 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...

you have assign menuitem's style property declaring <style> child element of <menuitem.style> element.

<menuitem ischeckable="true" ischecked="true">     <menuitem.style>         <style targettype="menuitem">             <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.style> </menuitem> 

Comments