簡體   English   中英

如何使用ContentTemplateSelector動態更改ListViewItem(加載后)

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

我有一個ListView,當控件第一次加載內容時,使用ItemTemplateSelector正確格式化了ListViewItem。 使用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來選擇其他模板?

我認為加載后不能動態更改單個ListViewItem模板。 但是您可以使用ItemContainerStyle在特定事件上自定義模板,例如“未聚焦”,“選定”,“按下...”。這是一個示例如何在Metro / WinRT應用程序的ListView的項目單擊上設置不同的背景顏色?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM