wpf controls - C# WPF ToggleButton Changing more than one property in a trigger? -
i have togglebutton , when clicked want change background , content. content changes correctly, background changes, instead of specified background value, default (?) blue-ish. in previous struggles background change, not content. done differently, though, w/ datatrigger instead of method below.
i'm using c# wpf , mvvm , bind content property , when binded ischecked property changed, change property in viewmodel, hoping not have that. maybe it's correct way?
here's code 1/2 works:
<togglebutton name="axis3absincbutton" ischecked="{binding path=usercontrolonestatic.motionparameters.axis3absorincoption, source={staticresource locator}}"> <togglebutton.style> <style targettype="{x:type togglebutton}"> <setter property="togglebutton.background" value="goldenrod"/> <setter property="togglebutton.content" value="abs" /> <style.triggers> <trigger property="ischecked" value="true"> <setter property="togglebutton.background" value="green" /> <setter property="togglebutton.content" value="inc" /> </trigger> </style.triggers> </style > </togglebutton.style> </togglebutton>
this close, have lost border of togglebutton:
<togglebutton name="axis3absincbutton" grid.row="2" grid.column="13" grid.columnspan="2" grid.rowspan="1" focusable="true" ischecked="{binding path=usercontrolonestatic.motionparameters.axis3absorincoption, source={staticresource locator}}"> <togglebutton.template> <controltemplate targettype="{x:type togglebutton}"> <border cornerradius="3" borderthickness="1" background="{templatebinding background}"> <contentpresenter margin="3" horizontalalignment="center" verticalalignment="center" /> </border> <controltemplate.triggers> <trigger property="ischecked" value="false"> <setter property="background" value="goldenrod"> </setter> </trigger> <trigger property="ischecked" value="true"> <setter property="background" value="blue" /> </trigger> </controltemplate.triggers> </controltemplate> </togglebutton.template> <togglebutton.style> <style targettype="{x:type togglebutton}"> <setter property="togglebutton.content" value="abs" /> <style.triggers> <trigger property="ischecked" value="true"> <setter property="togglebutton.content" value="inc" /> </trigger> </style.triggers> </style > </togglebutton.style> </togglebutton>
your xaml code correct. when click togglebutton, background color changed green. it's changing when move mouse button. when mouse coursor on togglebutton, has blue color.
edit: try this:
<togglebutton name="axis3absincbutton" grid.row="2" grid.column="13" grid.columnspan="2" grid.rowspan="1" focusable="true" ischecked="{binding path=usercontrolonestatic.motionparameters.axis3absorincoption, source={staticresource locator}}"> <togglebutton.template> <controltemplate targettype="{x:type buttonbase}"> <border x:name="border" borderbrush="{templatebinding borderbrush}" borderthickness="{templatebinding borderthickness}" background="{templatebinding background}" snapstodevicepixels="true"> <contentpresenter x:name="contentpresenter" contenttemplate="{templatebinding contenttemplate}" content="{templatebinding content}" contentstringformat="{templatebinding contentstringformat}" focusable="false" horizontalalignment="{templatebinding horizontalcontentalignment}" margin="{templatebinding padding}" recognizesaccesskey="true" snapstodevicepixels="{templatebinding snapstodevicepixels}" verticalalignment="{templatebinding verticalcontentalignment}"/> </border> <controltemplate.triggers> <trigger property="button.isdefaulted" value="true"> <setter property="borderbrush" targetname="border" value="{dynamicresource {x:static systemcolors.highlightbrushkey}}"/> </trigger> <trigger property="isenabled" value="false"> <setter property="background" targetname="border" value="#fff4f4f4"/> <setter property="borderbrush" targetname="border" value="#ffadb2b5"/> <setter property="textelement.foreground" targetname="contentpresenter" value="#ff838383"/> </trigger> </controltemplate.triggers> </controltemplate> </togglebutton.template> <togglebutton.style> <style targettype="{x:type togglebutton}"> <setter property="togglebutton.background" value="goldenrod"/> <setter property="togglebutton.content" value="abs" /> <style.triggers> <trigger property="ischecked" value="true"> <setter property="togglebutton.background" value="green" /> <setter property="togglebutton.content" value="inc" /> </trigger> </style.triggers> </style > </togglebutton.style> </togglebutton>
Comments
Post a Comment