wpf Get object type in xaml triggers -
i use triggers depend on local class types. common case general control styles, have class-dependent contentcontrols. scenario:
1) usercontrol implements listbox 'myusercontrol'
2) large listbox style, applies listbox control inside usercontrol. style has empty contentcontrol (that filled label / stackpanel)
<contentcontrol name="specificlabel"></contentcontrol>
3) there contentcontrols defined each specific derived class
<controltemplate x:key="listbox1template"> <label... </controltemplate> <controltemplate x:key="listbox2template"> <stackpanel... </controltemplate>
4) depending on derived class of mylistboxcontrol, template of contentcontrol chosen datatriggers:
<datatrigger binding="{binding elementname=myusercontrol, path=datatype}" value="{x:type local:mylistbox1}"> <setter targetname="specificlabel" property="template" value="{staticresource listbox1template}"/> </datatrigger> <datatrigger binding="{binding elementname=myusercontrol, path=datatype}" value="{x:type local:mylistbox2}"> <setter targetname="specificlabel" property="template" value="{staticresource listbox2template}"/> </datatrigger>
therefore, base class offers datatype property:
public type datatype { { return this.gettype(); } }
this looks there must simpler ways. possible local type in xaml only, without using property ?
i use datatemplate.datatype property , let wpf doing work.no triggers, no additional datatype property.
<datatemplate datatype="{x:type local:mylistbox1}"> <label... </datatemplate>
Comments
Post a Comment