c# - WPF Custom Component Datagrid binding -
so, trying perform databinding custom component have, can't seem find information on how so. have custom component in main window have bindning property...
<local:multicolumncombobox itemssource="{binding customers}" x:name="newcombo"></local:multicolumncombobox>
and in custom component...
<datagrid itemssource="{binding itemssource}" name="datagrid"></datagrid>
if knows how this, guidance appreciated :)
edit
public static readonly dependencyproperty itemssourceproperty = dependencyproperty.register("itemssource", typeof(ilist<customer>), typeof(multicolumncombobox)); public multicolumncombobox() { initializecomponent(); } //items source binding public ilist<customer> itemssource { { return (ilist<customer>)getvalue(itemssourceproperty); } set { system.console.writeline("binding"); system.console.writeline(value); setvalue(itemssourceproperty, value); } }
i've gotten binding error seeing when pass wrong ownertype dependencyproperty.register method... please check make sure you're using typeof(multicolumncombobox) shown below.
/// <summary> /// interaction logic multicolumncombobox.xaml /// </summary> public partial class multicolumncombobox : usercontrol { /// <summary> /// creates dependency property collection display. /// </summary> public static readonly dependencyproperty itemssourceproperty = dependencyproperty.register("itemssource", typeof(ilist<customer>), typeof(multicolumncombobox)); /// <summary> /// property gets collection that's being displayed. /// </summary> public ilist<customer> itemssource { { return (ilist<customer>)getvalue(itemssourceproperty); } set { setvalue(itemssourceproperty, value); } } public multicolumncombobox() { initializecomponent(); } }
also, make sure set binding elementname in usercontrol has right datacontext.
<usercontrol x:class="dependencypropertyexample.multicolumncombobox" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:name="usercontrol1"> <grid> <datagrid itemssource="{binding path=itemssource, elementname=usercontrol1}" /> </grid> </usercontrol>
Comments
Post a Comment