wpf - Custom DependencyProperty on Style.Trigger -
for usercontrol
declared dependencyproperty
:
public static readonly dependencyproperty deselectedpresentationmodeproperty = dependencyproperty.register( "deselectedpresentationmode", typeof(int), typeof(myusercontrol), new frameworkpropertymetadata(1,frameworkpropertymetadataoptions.affectsrender | frameworkpropertymetadataoptions.bindstwowaybydefault)); public static readonly dependencyproperty selectedpresentationmodeproperty = dependencyproperty.register( "selectedpresentationmode", typeof(int), typeof(myusercontrol), new frameworkpropertymetadata(1, frameworkpropertymetadataoptions.affectsrender | frameworkpropertymetadataoptions.bindstwowaybydefault));
now want use these properties within multitrigger:
<style targettype="{x:type listboxitem}" basedon="{staticresource {x:type listboxitem}}" x:key="myusercontrolitemstyle"> <style.triggers> <multitrigger> <multitrigger.conditions> <condition property="isselected" value="false" /> <condition property="gui:myusercontrol.deselectedpresentationmode" value="0" /> </multitrigger.conditions> <multitrigger.setters> <setter property="contenttemplate" value="{staticresource presentationmodeicononly}" /> </multitrigger.setters> </multitrigger> <multitrigger> <multitrigger.conditions> <condition property="isselected" value="false" /> <condition property="gui:myusercontrol.deselectedpresentationmode" value="1" /> </multitrigger.conditions> <multitrigger.setters> <setter property="contenttemplate" value="{staticresource presentationmodesimple}" /> </multitrigger.setters> </multitrigger> <multitrigger> <multitrigger.conditions> <condition property="isselected" value="true" /> <condition property="gui:myusercontrol.selectedpresentationmode" value="0" /> </multitrigger.conditions> <multitrigger.setters> <setter property="contenttemplate" value="{staticresource presentationmodeextended}" /> </multitrigger.setters> </multitrigger> <multitrigger> <multitrigger.conditions> <condition property="isselected" value="true" /> <condition property="gui:myusercontrol.selectedpresentationmode" value="1" /> </multitrigger.conditions> <multitrigger.setters> <setter property="contenttemplate" value="{staticresource presentationmodeicononly}" /> </multitrigger.setters> </multitrigger> </style.triggers> </style> ... ... <listbox ... itemcontainerstyle="{staticresource myusercontrolitemstyle}"/>
but if use myusercontrol project, there no reaction if change dependencyproperty
. whether use xaml
e.g:
<window ... x:class="wpfcontrolstester.mainwindow" title="mainwindow"> <grid> <gui:myusercontrol name="test"/> <slider minimum="0" maximum="1" value="{binding selectedpresentationmode, elementname=test}" /> <slider minimum="0" maximum="1" value="{binding deselectedpresentationmode, elementname=test}" /> </grid>
or if use kind of manipulation value this.test.deselectedpresentationmode = 0;
on event or smth else.
i used wpf inspector "debug" triggers, , both properties had default value (1). mistake or should add update triggers?
edit : changed false "mycontrol "myusercontrol"
you can try multidatatrigger instead in order property changes:
<style.triggers> <multidatatrigger> <multidatatrigger.conditions> <condition binding="{binding isselected, relativesource={relativesource self}}" value="false" /> <condition binding="{binding deselectedpresentationmode, relativesource={relativesource ancestortype={x:type myusercontrol}}}" value="0" /> </multidatatrigger.conditions> <multidatatrigger.setters> <setter property="contenttemplate" value="{staticresource presentationmodeicononly}" /> </multidatatrigger.setters> </multidatatrigger> </style.triggers>
thanks
Comments
Post a Comment