2013-02-25 6 views
0

CustomTreeView에서 선언 한 스타일을 어떻게 확장 할 수 있습니까? 그래서 나는 lightgray 전경과 녹색 배경을 가지고 있습니까?사용자 지정 TreeView 항목 컨테이너 스타일을 확장 하시겠습니까?

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> 

답변

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>