c# - Conditional Static Resource For Itemsource -
at moment in order fix bug telerik, itemssource must pointing viewmodel i'm working with.
relationship.xaml
<usercontrol.resources> <client:personviewmodel x:key="myviewmodel"/> </usercontrol.resources>
where it's used.
<telerik:gridviewcomboboxcolumn header="relationship" itemssource="{binding gridrelationshiptypes, mode=twoway, source={staticresource myviewmodel}}" datamemberbinding="{binding relationshiptype}" selectedvaluememberpath="id" displaymemberpath="name" isreadonly="false"/>
i have 4 other view models logic needs applied to. don't want create 5 different usercontrols such small thing. i'm wondering if can create method such it'll check current viewmodel type , use corresponding viewmodel.
pseudocode - viewmodeltypes enum.
public void staticresourctouse(viewmodeltypes viewmodeltype) { if (viewmodeltype == viewmodeltypes.personviewmodel) use personviewmodel resources if (viewmodeltype == viewmodeltypes.businessviewmodel) use businessviewmodel resources }
if understand correctly want switch view based on view model.
use contentcontrol
display data, , swap out contenttemplate
in trigger based on property changes.
here's example in rachel lim's blog swaps template based on bound property:
<datatemplate x:key="cartemplate" targettype="{x:type local:yourviewmodel}"> <textblock text="i'm car" /> </datatemplate> <datatemplate x:key="tracktemplate" targettype="{x:type local:yourviewmodel}"> <textblock text="i'm track" /> </datatemplate> <datatemplate datatype="{x:type local:yourviewmodel}"> <contentcontrol content="{binding }"> <contentcontrol.style> <style targettype="{x:type contentcontrol}"> <setter property="contenttemplate" value="{staticresource cartemplate}" /> <style.triggers> <datatrigger binding="{binding yourtype}" value="track"> <setter property="contenttemplate" value="{staticresource tracktemplate}" /> </datatrigger> </style.triggers> </style> </contentcontrol.style> </contentcontrol> </datatemplate>
Comments
Post a Comment