0

CustomTreeView で宣言したスタイルを拡張するにはどうすればよいですか? 明るい灰色の前景と緑の背景を持つようにするにはどうすればよいですか?

CustomTreeView.xaml

<TreeView x:Class="WpfApplication17.CustomTreeView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <TreeView.ItemContainerStyle>
        <Style TargetType="{x:Type TreeViewItem}">
            <Setter Property="Foreground" Value="LightGray"/>
        </Style>
    </TreeView.ItemContainerStyle>
</TreeView>

Window.xaml

<Window x:Class="WpfApplication17.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WpfApplication17">
    <local:CustomTreeView ItemsSource="{Binding Data}">
        <local:CustomTreeView.ItemContainerStyle>
            <Style TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource {x:Type TreeViewItem}}">
                <Setter Property="Background" Value="Green"/>
            </Style>
        </local:CustomTreeView.ItemContainerStyle>
    </local:CustomTreeView>
</Window>
4

1 に答える 1

0

これが正しいアプローチかどうかはわかりませんが、結局それを使用しました。

<TreeView x:Class="WpfApplication17.CustomTreeView"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
        <TreeView.Resources>
            <Style x:Key="m_itemContainerStyle" TargetType="{x:Type TreeViewItem}">
                <Setter Property="Foreground" Value="LightGray"/>
            </Style>
        </TreeView.Resources>

        <TreeView.ItemContainerStyle>
            <Style BasedOn="{StaticResource m_itemContainerStyle}" TargetType="{x:Type TreeViewItem}">

            </Style>
        </TreeView.ItemContainerStyle>
    </TreeView>


    <Window x:Class="WpfApplication17.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:local="clr-namespace:WpfApplication17">
        <local:CustomTreeView ItemsSource="{Binding Data}">
            <local:CustomTreeView.ItemContainerStyle>
                <Style BasedOn="{StaticResource m_itemContainerStyle}"  TargetType="{x:Type TreeViewItem}">
                    <Setter Property="Background" Value="Green"/>
                </Style>
            </local:CustomTreeView.ItemContainerStyle>
        </local:CustomTreeView>
    </Window>
于 2013-02-25T22:56:43.353 に答える