c# - Trouble setting a DataTrigger in WPF -


i have combobox , button on main view, , want apply style button such when combobox index set 1, button becomes visible (initially it's hidden). xaml code:

<grid>     <stackpanel orientation="vertical" margin="10">         <combobox name="combobox"/>          <button name="mybtn" content="hello" visibility="hidden">              <button.style>                  <style targettype="{x:type button}">                      <style.triggers>                          <datatrigger binding="{binding elementname=combobox, path=selectedindex}" value="1">                              <setter property="visibility" value="visible"/>                           </datatrigger>                       </style.triggers>                   </style>               </button.style>          </button>      </stackpanel> </grid> 

someone asked question here, , i'm doing pretty same thing, doesn't work, button remains hidden when index changed 1. comobox being populated in code behind 2 items. appreciated.

the problem dependency property values set locally (like you've done visibility) have higher precedence set style trigger. such, when trigger hit, won't override value you've set.

the simple solution instead set default value in style setter:

    <button name="mybtn" content="hello">          <button.style>              <style targettype="{x:type button}">                  <setter property="visibility" value="hidden"/>                  <style.triggers>                      <datatrigger binding="{binding elementname=combobox, path=selectedindex}" value="1">                          <setter property="visibility" value="visible"/>                       </datatrigger>                   </style.triggers>               </style>           </button.style>      </button> 

and trigger override property value when hit.

while you're @ it, should have @ this link lists precedence order setting dp values.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -