Metro app: change GridView.ItemTemplate programmatically

[亡魂溺海] 提交于 2019-12-23 02:38:14

问题


I've a GridView in my Xaml with a given DataTemplate set a StaticResource:

<GridView
        x:Name="itemGridView"
        ItemsSource="{Binding Source={StaticResource itemsViewSource}}"
        ItemTemplate="{StaticResource MyItemTemplate }" 
        SelectionMode="None"
        IsItemClickEnabled="True"
        ItemClick="ItemView_ItemClick"/>

By clicking on a button in the AppBar, I'd like to restyle this template by applying another DataTemplate - MyItemTemplateWide to this particular list.

My datatemplates are stored in an Xaml file referenced as a ResourceDictionary.

I'd like to load the new DataTemplate in the C# codebehind.

Would the DataTemplateSelector help me here (by setting any hidden value in Xaml for example)?


回答1:


u can create multiple grid view with different template and change visibilty of the grid as per necessaties.

make grid view visible that is in use and make other visibility false

Note: location of gridview to be placed in xaml must be same for all. means gird.row and grid.column must be same for every gridview if placing it in grid.



来源:https://stackoverflow.com/questions/11657618/metro-app-change-gridview-itemtemplate-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!