wpf - ToggleButton IsChecked trigger -
i writing 1 application have togglebutton
, other few controls on ui. want achieve bellow 2 things when state of togglebutton
ischecked
.
1) hide few controls e.g. button1,button2 etc. in below example 2) change 'content' of togglebutton 'show'
i can achieve point no 2 don't know how access other control , set properties inside trigger
. xaml code shown below:
<grid> <grid.rowdefinitions> <rowdefinition height="108*" /> <rowdefinition height="107*" /> <rowdefinition height="96*" /> </grid.rowdefinitions> <grid.columndefinitions> <columndefinition width="209*" /> <columndefinition width="161*" /> <columndefinition width="133*" /> </grid.columndefinitions> <togglebutton x:name="tg" height="20" width="80" grid.column="1" margin="2,38,79,49" grid.row="1"> <togglebutton.style> <style targettype="{x:type togglebutton}"> <setter property="content" value="hide" /> <style.triggers> <trigger property="ischecked" value="true"> <setter property="{binding elementname=button1,path=content}" value="show" /> </trigger> </style.triggers> </style> </togglebutton.style> </togglebutton> <button content="button1" height="23" horizontalalignment="left" margin="45,28,0,0" name="button1" verticalalignment="top" width="75" /> <button content="button2" height="23" horizontalalignment="left" margin="38,28,0,0" name="button2" verticalalignment="top" width="75" grid.column="1" /> </grid>
question: when user clicks on toggle button 'tg' want hide 'button1','button2' , when state of toggle button changes un-check again show button1.
how can toggle visibility of button1 togglebutton
's ischecked
property?
in resources declare booltovisibilityconverter
given below:
<window.resources> <booleantovisibilityconverter x:key="booltovis" /> </window.resources>
then set visibility of button1 binding:
<button content="button1" height="23" horizontalalignment="left" margin="45,28,0,0" name="button1" verticalalignment="top" width="75" visibility="{binding elementname=tg, path=ischecked, converter={staticresource booltovis}}"/>
Comments
Post a Comment