2

これをXAMLで使用して、JoshSmithのサンプルコードに基づくビューモデルからツリービューの子をロードします

<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 に答える