简体   繁体   English

如何使用ContentTemplateSelector动态更改ListViewItem(加载后)

[英]How to change a ListViewItem with ContentTemplateSelector Dynamically (after load)

I have a ListView, with ListViewItem s being properly formatted using ItemTemplateSelector when the control first loads content. 我有一个ListView,当控件第一次加载内容时,使用ItemTemplateSelector正确格式化了ListViewItem。 The data is properly coded using INotifyPropertyChanged. 使用INotifyPropertyChanged对数据进行了正确编码。

My question is: How do I cause a single ListViewItem to update it's DataTemplate after the ListView has already loaded the data? 我的问题是:在ListView已加载数据后,如何使单个ListViewItem更新其DataTemplate? I'm not sure if I need to use a setter or a task or a simple binding. 我不确定是否需要使用setter或任务或简单的绑定。 Has anyone done this already? 有人做过吗?

My ListView code: 我的ListView代码:

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

This works well when the data first loads, but when a variable changes, how do I get the ItemTemplateSelector to choose a different template? 首次加载数据时,此方法效果很好,但是当变量更改时,如何获取ItemTemplateSelector来选择其他模板?

I don't think you can change single ListViewItem template dynamically after loaded. 我认为加载后不能动态更改单个ListViewItem模板。 But you can use ItemContainerStyle to custom your template on specific event, like Unfocused, Selected, Pressed... Here is a sample How do I set a different background colour on item click of ListView for metro/WinRT app? 但是您可以使用ItemContainerStyle在特定事件上自定义模板,例如“未聚焦”,“选定”,“按下...”。这是一个示例如何在Metro / WinRT应用程序的ListView的项目单击上设置不同的背景颜色?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM