c# - Hub with dynamic HubSections with GridViews and DataBinding -
i create hub several hubsections via code. each hubsection owns single gridview every hubsection table (fullscreen) , swipe left/right view every table. in xaml page hub other stuff should done code. hubsections should created @ runtime. use local settings storage save information this, how many hubsections etc. creating new hubsections no problem i'm stuck @ adding gridview each hubsection because don't understand logic here. looks have add datatemplate , gridview attempts failed.
note: each gridview has it's own databinding observable collection.
so how add (?datatemplate?) gridview databinding hubsection ?
with datatemplate build layout. have used in project following template show few data per day , create 1 section each day:
<page.resources> <collectionviewsource x:name="hubviewmodel"/> <datatemplate x:key="datatemplate"> <grid background="transparent" width="300" horizontalalignment="stretch" verticalalignment="stretch" margin="0,0,0,20"> <grid.rowdefinitions> <rowdefinition height="*"/> <rowdefinition height="*"/> </grid.rowdefinitions> <stackpanel grid.row="0" horizontalalignment="center"> <textblock text="{binding sumshipmentssa}" style="{themeresource headertextblockstyle}" textalignment="center" textwrapping="nowrap"/> </stackpanel> <stackpanel grid.row="1" horizontalalignment="center"> <stackpanel orientation="horizontal"> <textblock x:uid="summaryhubnat" text="national" fontsize="10" width="100" verticalalignment="center" margin="0,0,20,0"/> <textblock text="{binding countshipmentsnationalsa}" style="{themeresource bodytextblockstyle}" textwrapping="nowrap"/> </stackpanel> <stackpanel orientation="horizontal"> <textblock x:uid="summaryhubint" text="international" fontsize="10" width="100" verticalalignment="center" margin="0,0,20,0"/> <textblock text="{binding countshipmentsinternationalsa}" style="{themeresource bodytextblockstyle}" textwrapping="nowrap"/> </stackpanel> <stackpanel orientation="horizontal"> <textblock x:uid="summaryhubcharter" text="charter" fontsize="10" width="100" verticalalignment="center" margin="0,0,20,0"/> <textblock text="{binding countshipmentschartersa}" style="{themeresource bodytextblockstyle}" textwrapping="nowrap"/> </stackpanel> </stackpanel> </grid> </datatemplate> </page.resources> . . <hub x:name="mainhub" datacontext="{binding source={staticresource hubviewmodel}}" margin="0,0,0,20"/>
in code page used following method create section:
private void addhubsection(ienumerable<daysummary> list) { if (list != null) { list = list.orderbydescending(x => x.date); foreach (var item in list) { if (item.date.date.equals(datetime.now.date)) { continue; } hubsection hubsection = new hubsection(); textblock headertextblock = new textblock(); headertextblock.text = item.date.tostring("dddd dd.mmm"); headertextblock.fontsize = 15; hubsection.header = headertextblock; hubsection.margin = new thickness(0); object datatemplate; this.resources.trygetvalue("datatemplate", out datatemplate); hubsection.contenttemplate = datatemplate datatemplate; hubsection.datacontext = item; hubsection.doubletapped += hubsection_doubletapped; mainhub.sections.add(hubsection); } } }
i think example can have fun while trying.
Comments
Post a Comment