i use datatrigger change checkbox image source icon.
<checkbox content="an image checkbox label" foreground="black" margin="73,103,27,142" isthreestate="true" > <checkbox.template> <controltemplate targettype="{x:type checkbox}"> <stackpanel orientation="horizontal"> <image> <image.style> <style> <style.triggers> <datatrigger binding="{binding ischecked, relativesource={relativesource ancestortype={x:type checkbox}}}" value="true"> <setter property="image.source" value="/images/checkbox.ico" /> </datatrigger> <datatrigger binding="{binding ischecked, relativesource={relativesource ancestortype={x:type checkbox}}}" value="false"> <setter property="image.source" value="/images/checkboxuncheck.ico" /> </datatrigger> <datatrigger binding="{binding ischecked, relativesource={relativesource ancestortype={x:type checkbox}}}" value="{x:null}"> <setter property="image.source" value="/images/delete_12x12.png" /> <setter property="image.width" value="10" /> <setter property="image.height" value="10" /> </datatrigger> </style.triggers> </style> </image.style> </image> <contentpresenter content="{templatebinding content}" margin="5,0,0,0" /> </stackpanel> </controltemplate> </checkbox.template> </checkbox>
is way set checkbox style(or image) default states when ischecked=false value="false
or inderterminate value="{x:null}
?
if want apply custom template when checkbox
checked apply style
trigger
checkbox
:
<checkbox content="an image checkbox label" foreground="black" margin="73,103,27,142" isthreestate="true" > <checkbox.style> <style targettype="checkbox"> <style.triggers> <trigger property="ischecked" value="true"> <setter property="template"> <setter.value> <controltemplate targettype="{x:type checkbox}"> <stackpanel orientation="horizontal"> <image source="/images/checkbox.ico" /> <contentpresenter content="{templatebinding content}" margin="5,0,0,0" /> </stackpanel> </controltemplate> </setter.value> </setter> </trigger> </style.triggers> </style> </checkbox.style> </checkbox>
Comments
Post a Comment