xaml - WinRT hardcoded ListViewItem vs. DataTemplate, why do they not look/work the same? -
i'm new winrt apologies if silly question. i've created following listview:
<listview x:name="mylistview1" grid.row="1" margin="120,300,0,0" width="500" horizontalalignment="left"> <listviewitem background="dodgerblue"> <grid> <grid.columndefinitions> <columndefinition width="200" /> <columndefinition width="300" /> </grid.columndefinitions> <textblock text="hardcoded value 1" grid.column="0"></textblock> <textblock text="hardcoded value 2" grid.column="1"></textblock> </grid> </listviewitem> </listview>
this looks way want look, , if click item select whole row. however, if move datatemplate doesn't same, , can no longer click whole row. (if add itemcontainerstyle target type listviewitem , set background yellow, fill it's same size hardcoded listitem, can click yellow outline select it.) code:
<listview x:name="mylistview2" itemtemplate="{staticresource mytemplate}" itemssource="{binding mydata}" grid.row="1" margin="120,0,0,0" width="500" horizontalalignment="left"> </listview>
and in standardstyles.xaml:
<datatemplate x:key="mytemplate"> <listviewitem background="dodgerblue"> <grid> <grid.columndefinitions> <columndefinition width="200" /> <columndefinition width="300" /> </grid.columndefinitions> <textblock text="{binding mydataone}" grid.column="0"></textblock> <textblock text="{binding mydatatwo}" grid.column="1"></textblock> </grid> </listviewitem> </datatemplate>
i don't understand why don't look/work same - shouldn't populated exact same code when bind it? need make work?
the problem there way created datatemplate. remember listviewitem wrapper added object needs displayed in list, when create datatemplate contains listviewitem wrapping object twice. need remove listviewitem element datatemplate
<datatemplate x:key="mytemplate"> <grid background="dodgerblue"> <grid.columndefinitions> <columndefinition width="200" /> <columndefinition width="300" /> </grid.columndefinitions> <textblock text="{binding mydataone}" grid.column="0"></textblock> <textblock text="{binding mydatatwo}" grid.column="1"></textblock> </grid></datatemplate>
Comments
Post a Comment