c# - binding a control with a observable collection -
in xaml, how display observablecollection in expander control grid when expand it?
public class boundpoco ( public string expandertext { set; get; } public observablecollection<displaydetail> { set; get; } ) public class displaydetail { public string firstdisplaycolumn { set; get; } public string seconddisplaycolumn; { set; get; } }
you should use items control within expander control achieve this.
firstly sort code behind errors out - had stray semicolon on "seconddisplaycolumn":
public string seconddisplaycolumn { set; get; }
... , had no name on main observable collection property!
public observablecollection<displaydetail> displaydetails { set; get; }
then, if you're not using dependency properties or inotifypropertychanged - create xaml display data (with name 'items'):
<expander name="myexpander" background="tan" horizontalalignment="left" header="my expander" expanddirection="down" isexpanded="true" width="auto"> <itemscontrol name="items"> <itemscontrol.itemtemplate> <datatemplate> <grid> <grid.columndefinitions> <columndefinition /> <columndefinition /> </grid.columndefinitions> <textblock grid.column="0" text="{binding firstdisplaycolumn}"/> <textblock grid.column="1" text="{binding seconddisplaycolumn}"/> </grid> </datatemplate> </itemscontrol.itemtemplate> </itemscontrol> </expander>
then can populate observable collection , set items source in codebehind:
displaydetails.add(new displaydetail() { firstdisplaycolumn = "fieldname1", seconddisplaycolumn = "fieldvalue1" }); displaydetails.add(new displaydetail() { firstdisplaycolumn = "fieldname2", seconddisplaycolumn = "fieldvalue2" }); displaydetails.add(new displaydetail() { firstdisplaycolumn = "fieldname3", seconddisplaycolumn = "fieldvalue3" }); items.itemssource = displaydetails;
Comments
Post a Comment