c# - MVVM: Bind ContentControl to CheckBox -
i have contentcontrol
want bind it's content
property ischecked
property of checkbox
. using mvvm, idea thought of doing this:
<contentcontrol contenttemplate="{binding currenttemplate}"/> <checkbox ischecked="{binding isnewcustumor}"/>
and in view model listen isnewcustumor
property change , assign corresponding datatemplate
currenttemplate
property, think involve using views in view model not mvvm
. idea write converter class, don't know how should implement it.
so can help?
as far understand want switch template based on value of property isnewcustomer
. 1 way achieve this, using style trigger. advantage is, purely xaml , easy read:
<contentcontrol> <contentcontrol.style> <style targettype="contentcontrol> <style.triggers> <datatrigger binding="{binding isnewcustomer}" value="true"> <setter property="contenttemplate" value="set template new customers here"> </datatrigger> </style.triggers> <setter property="contenttemplate" value="set template not new customers here"> </style> <contentcontrol.style> <contentcontrol>
Comments
Post a Comment