[英]WinrtXamlToolkit TreeView ItemContainerStyleSelector not firing
我使用的TreeView從控制WinrtXamlToolkit在UWP應用。 我想根據條件將不同的樣式應用於某些TreeViewItem,因此我創建了一個類,TreeViewItemStyleSelector,它從StyleSelector派生,並且重寫SelectStyleCore函數。
public Style ResourceStyle { get; set; }
public Style ClassroomStyle { get; set; }
protected override Style SelectStyleCore(object item, DependencyObject container)
{
// control never reaches here.
// logic to apply style
}
然后在xaml中我像這樣使用它。
頁內資源
<StyleSelectors:TreeViewItemStyleSelector ResourceStyle="{StaticResource AStyle}" ClassroomStyle = "{StaticResource BStyle}"/>
然后在頁面的后面。
<wxtControls:TreeView ItemsSource="{Binding StructureViewModels}" ItemContainterStyleSelector="{StaticResource TreeViewItemStyleSelector}" />
問題是從不調用SelectStyleCore覆蓋。 有人知道為什么嗎?
盡管我有一些理論,但我不確定這不起作用的原因是什么。 一個是-從未實施過。 也許至少它在根級別上應該起作用,因為它是ItemsControl
,但是由於它的實現方式(分層) ItemContainerStyleSelector
必須從TreeView
轉發到TreeViewItems
,而實際上不是。
我還沒有機會嘗試重現它,但是如果我要修復它或變通解決-我首先嘗試在HeaderedItemsControl.cs
轉發該屬性-大致在其上顯示“ // Note: this is where we would apply the HeaderTemplateSelector (...) (if implemented)
。 替代方法(如果您不想修改工具包的代碼)可能是為TreeViewItem
指定模板,並在模板中-對於要對不同數據項使用不同的模板部件,請使用StyleSelector
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.