c# - Binding DataTemplateSelector with treeview item programmatically in WPF -
i not able bind data template selector tree view item programmatically. here have created parameterized data template selector , can not bound tree view in xaml. here code data template selector
public class mytemplate : datatemplateselector { private ivm_manytoonemapping _viewmodel; public mytemplate(ivm_manytoonemapping viewmodel) { _viewmodel = viewmodel; } }
tried approach : mytemplate obj= new mytemplate(viewmodel) treeviewlist.itemtemplateselector = obj;
it not working.
this not how datatemplateselector
works:
here example:
public class templateselector : datatemplateselector { //you override function select data template based in given item public override system.windows.datatemplate selecttemplate(object item, system.windows.dependencyobject container) { if(item myviewmodel1) return datatemplate1; if(item myviewmodel2) return datatemplate2; return base.selecttemplate(item, container); } }
but if in code behind, why need datatemplateselector
?
this nice example, how things bindable , more dynamic
Comments
Post a Comment