我有以下2个DataTemplates:
<DataTemplate x:Key="ItemPhoto">
<StackPanel>
<Image Source="{Binding Thumbail}" Height="80" Width="80" HorizontalAlignment="Stretch" Stretch="UniformToFill"/>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="ItemAlbum">
<StackPanel>
<Image Source="{Binding Thumbail}" Height="100" Width="100" HorizontalAlignment="Stretch" Stretch="UniformToFill"/>
</StackPanel>
</DataTemplate>
和1 GridView
<GridView Grid.Row="1" Name="lstFlickrControl"
SelectionMode="Multiple"
ItemTemplate="{StaticResource ItemPhoto}"
ItemClick="lstFlickrControl_ItemClick" Holding="lstFlickrControl_Holding">
<GridView.ItemContainerStyle>
<Style TargetType="FrameworkElement">
<Setter Property="Margin" Value="2"/>
</Style>
</GridView.ItemContainerStyle>
</GridView>
我希望当我单击照片菜单GridView时它应该加载ItemPhoto DataTemple但是当我单击相册菜单GridView时它应该加载ItemAlbums DataTemple。有人可以提出一些建议吗?
答案 0 :(得分:0)
尝试这种方式,例如在相册菜单上点击更改ItemTemplate
以使用ItemAlbum
DataTemplate
:
lstFlickrControl.ItemTemplate = (DataTemplate)this.Resources["ItemAlbum"];
注意:您可能需要将上面示例中的this
更改为您定义DataTemplate
s