2

我在 XAML 中使用它来从基于 Josh Smith 的示例代码的视图模型中加载树视图子

<TreeView.ItemContainerStyle>
        <Style TargetType="{x:Type TreeViewItem}">
            <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
            <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
        </Style>
</TreeView.ItemContainerStyle>

这会导致我用于 TreeViewItem 的主题被忽略。它使所选项目的文本变为黑色,背景变为深蓝色,因此难以阅读。有没有办法同时使用主题和上面的代码?

4

2 回答 2

3

尝试设置BasedOn{StaticResource {x:Type TreeViewItem}}.

这将采用默认样式TreeViewItems(由主题提供)作为您的样式的基础。

于 2011-06-03T22:03:22.353 回答
0

只是形成的代码:

<TreeView.ItemContainerStyle> 
    <Style TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource {x:TypeTreeViewItem}"> 
        <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" /> 
        <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" /> 
    </Style> 
</TreeView.ItemContainerStyle>
于 2013-05-09T20:58:38.380 回答