c# - Set TabItem DataContext Inidividiually? -
i have tabcontrol items in based on class. i'd bind class tabitem can have mix of user controlled , class controlled tabitems.
i have.
xaml
<window.resources> <textblock x:key="tabitem_prefab" text="{binding name}"/> </window.resources> <tabcontrol> <tabitem header="a" name="tabcontrol_a"> <staticresource resourcekey="tabitem_prefab"/> </tabitem> <tabitem header="b" name="tabcontrol_b"> <staticresource resourcekey="tabitem_prefab"/> </tabitem> <tabitem header="options"> <textblock text="stuff"/> </tabitem> </tabcontrol>
c#
public partial class mainwindow : window { public mainwindow() { initializecomponent(); viewmodeltest = new viewmodeltest() { name = "string" }; viewmodeltest b = new viewmodeltest() { name = "cheese" }; tabcontrol_a.datacontext = a; tabcontrol_b.datacontext = b; } } public class viewmodeltest { public string name { get; set; } }
the problem tab tabcontrol_a shows "cheese" when should bound 1 says "string".
what can prepare problem?
the problem lies within staticresource tabitem_prefab. seems me usual binding works
<tabcontrol> <tabitem header="a" name="tabcontrol_a"> <textblock text="{binding name}"/> </tabitem> <tabitem header="b" name="tabcontrol_b"> <textblock text="{binding name}"/> </tabitem> <tabitem header="options"> <textblock text="stuff"/> </tabitem> </tabcontrol>
show staticresource.
c# xaml binding datacontext
No comments:
Post a Comment