如何动态更改带有ContentTemplateSelector的ListViewItem(加载后)

时间:2012-10-10 12:16:16

标签: c# xaml windows-8 microsoft-metro visual-studio-2012

我有一个ListView,当控件首次加载内容时,ListViewItem使用ItemTemplateSelector正确格式化。使用INotifyPropertyChanged正确编码数据。

我的问题是:在ListView加载数据后,如何让单个ListViewItem更新它的DataTemplate?我不确定我是否需要使用setter或任务或简单的绑定。有没有人这样做过?

我的ListView代码:

        <ListView x:Name="lv_src_gStream" 
                  ItemsSource="{Binding Source={StaticResource CVS_src_gStream}}" 
                  PointerPressed="selectPost" 
                  SelectionMode="None" 
                  HorizontalContentAlignment="Stretch" 
                  ItemTemplateSelector="{StaticResource postTemplateSelector}">
        </ListView>

这在数据首次加载时效果很好,但是当变量发生变化时,如何让ItemTemplateSelector选择不同的模板?

1 个答案:

答案 0 :(得分:0)

我不认为你可以在加载后动态更改单个ListViewItem模板。 但您可以使用ItemContainerStyle在特定事件上自定义模板, 喜欢Unfocused,Selected,Pressed ...... 这是一个示例How do I set a different background colour on item click of ListView for metro/WinRT app?