xaml - C# WPF Binding DataGrid to TabControl -



xaml - C# WPF Binding DataGrid to TabControl -

i´m newbie in wpf , have problem data-binding. hope can help me:

here xaml- code:

<window x:class="wpfapplication4.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="mainwindow" height="350" width="525"> <grid> <tabcontrol name="maintabcontrol" itemssource="{binding}" margin="2,0,-2,0"> <tabcontrol.itemtemplate> <datatemplate> <stackpanel> <textblock text="{binding header}" tag="{binding rid}" /> </stackpanel> </datatemplate> </tabcontrol.itemtemplate> <tabcontrol.contenttemplate> <datatemplate> <datagrid itemssource="{binding dg}" /> </datatemplate> </tabcontrol.contenttemplate> </tabcontrol> </grid> </window>

so have tabcontrol binding observablecollection of tabs. each tab has textblock header , datagrid.

binding:

public mainwindow() { initializecomponent(); datagrid dg = new datagrid(); datagridtemplatecolumn xx = new datagridtemplatecolumn() { header = new textblock() { text = "edit", tag = "edit" } }; xx.width = new datagridlength(1, datagridlengthunittype.auto); dg.columns.add(xx); octabs.add(new octab() { header = "test1", rid = 1 , dg = dg}); octabs.add(new octab() { header = "test2", rid = 2 , dg = dg}); octabs.add(new octab() { header = "test3", rid = 3, dg = dg }); maintabcontrol.datacontext = octabs; }

and here tab- class:

public class octab : inotifypropertychanged { private string _header; private int _rid; private datagrid dg; public datagrid dg { { homecoming dg; } set { dg = value; notifypropertychanged("dg"); } } public string header { { homecoming _header; } set { _header = value; notifypropertychanged("header"); } } public int rid { { homecoming _rid; } set { _rid = value; notifypropertychanged("rid"); } } public event propertychangedeventhandler propertychanged; private void notifypropertychanged(string propertyname) { if (propertychanged != null) { propertychanged(this, new propertychangedeventargs(propertyname)); } } }

now problem: works fine, except datagrids each tab. datagrid empty (no columns,...) binding doesn´t work , don´t know why...

edit: possible, each tabitem has it´s own datagrid?

wpf xaml binding datagrid tabcontrol

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -