c# - How to switch between views using DataTemplate + Triggers -
i have requirement where user can switch view hierarchical data either tree or text in datagrid or flowchart.
the user can clicking toggle button say: switch mode. want in such way can handled within view viewmodel in 3 cases same.
how apply view viewmodel based on trigger.
if state of view show saved in enum property use contentcontrol , datatriggers example:
<contentcontrol> <contentcontrol.style> <style targettype="{x:type contentcontrol}"> <style.triggers> <datatrigger binding="{binding viewmode}" value="treemode"> <setter property="content"> <setter.value> <uc:treemodeview /> </setter.value> </setter> </datatrigger> <datatrigger binding="{binding viewmode}" value="gridmode"> <setter property="content"> <setter.value> <uc:gridmodeview /> </setter.value> </setter> </datatrigger> </style.triggers> </style> </contentcontrol.style> </contentcontrol> (as style used in 1 place, setting directly contentcontrol.style work, if want use in more 1 place should set contenttemplate instead, because otherwise there 1 view instance shared controls style not allowed wpf (of course content needs set something template applied))
you bind directly ischecked of togglebutton using elementname of course. relevant values true, false , {x:null}.
Comments
Post a Comment