c# - Binding to a property of a collection -
context
the wpf datagrid allows developers manually bind each column property of itemssource, this:
<datagrid itemssource="{binding people}" autogeneratecolumns="false"> <datagrid.columns> <datagridtextcolumn binding="{binding name}"/> <datagridtextcolumn binding="{binding age}"/> <datagridtextcolumn binding="{binding country}"/> </datagrid.columns> </datagrid>
the advantage of these column bindings visual studio display design-time warnings if bindings don't correspond property of objects in people collection. provide list of valid properties through intellisense.
i'm developing different type of grid , having trouble getting functionality. have developed this:
<my:grid itemssource="{binding people}"> <my:column property="name" /> <my:column property="age" /> <my:column property="country" /> </my:grid>
internally these string based properties looked through type.getproperty() @ runtime.
my question
how can implement property binding in datagrid example? have looked through decompiled source of datagrid , found datagridboundcolumn.binding of type bindingbase.
i reappropriated bindingbase custom grid i'm still not getting strong typing or intellisense options, because bindingbase has no idea type applies to, don't see how provide context needs.
change implemantion of property my:column.property dependency propertie. allow use bindings, maybe helps. intellisense around binding more deal of vs-xaml-designer , not code.
//http://msdn.microsoft.com/en-us/library/ms752914(v=vs.110).aspx public static readonly dependencyproperty propertyproperty = dependencyproperty.register( "property", typeof(boolean), ); public bool isspinning { { return (bool)getvalue(propertyproperty ); } set { setvalue(propertyproperty , value); } }
Comments
Post a Comment