2014-03-30 3 views
0

ExpressionDark 테마를 사용하는 WPF 응용 프로그램의 경우 TabControl을 사용하며 수정하지 않고 탭 컨트롤의 테마 스타일이 좋습니다.ExpressionDark 테마를 사용하는 WPF 응용 프로그램, TabItem 머리글 스타일을 확장하려는 경우

그러나 스타일 설정기를 통해 HeaderTemplate을 구현할 때 헤더 템플리트의 테마 스타일을 덮어 쓰는 것으로 보입니다.

내가 원하는 것은 내 탭 컨트롤의 헤더가 이미지를 포함 할 수 있도록 테마의 스타일을 확장하는 것입니다 (아래의 샘플 코드는 하드 코딩되었지만 궁극적으로 바운드되고 동적입니다).

TabItemHeaderTemplate 또는 에 표시 할 수있는 방법이 있나요 어떻게 든 테마의 템플릿에서 BasedOn을 할 항목을 TabItemHeaderTemplateSelected?

<UserControl x:Class="WpfApp1.ConfigControl" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     mc:Ignorable="d" 
     Background="{DynamicResource WindowBackgroundBrush}"> 

<UserControl.Resources> 
    <DataTemplate x:Key="TabItemHeaderTemplate" > 
     <Border> 
      <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center" > 
       <Image Height="32" Width="32" 
         Source="/Assets/Images/WarningIcon.png" /> 
       <TextBlock Text="{Binding}" VerticalAlignment="Center" Margin="10 0 0 0" FontSize="16" /> 
      </StackPanel> 
     </Border> 
    </DataTemplate> 
    <DataTemplate x:Key="TabItemHeaderTemplateSelected"> 
     <Button> 
      <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Center" > 
       <Image Height="32" Width="32" 
         Source="/Assets/Images/WarningIcon.png" /> 
       <TextBlock Text="{Binding}" VerticalAlignment="Center" Margin="10 0 0 0" FontSize="16" FontWeight="Bold" /> 
      </StackPanel> 
     </Button> 
    </DataTemplate> 
    <DataTemplate x:Key="TabItemContentTemplate"> 
     <ContentControl Content="{Binding}" /> 
    </DataTemplate> 
    <Style x:Key="TabItemContainerStyle" TargetType="TabItem" > 
     <Setter Property="Header" Value="{Binding}"/> 
     <Setter Property="HeaderTemplate" 
       Value="{StaticResource TabItemHeaderTemplate}"/> 
     <Setter Property="Content" Value="{Binding}"/> 
     <Setter Property="ContentTemplate" 
       Value="{StaticResource TabItemContentTemplate}"/> 
     <Style.Triggers> 
      <Trigger Property="IsSelected" Value="true"> 
       <Setter Property="HeaderTemplate" Value="{StaticResource TabItemHeaderTemplateSelected}" /> 
      </Trigger> 
      <Trigger Property="IsSelected" Value="false"> 
       <Setter Property="HeaderTemplate" Value="{StaticResource TabItemHeaderTemplate}" /> 
      </Trigger> 
     </Style.Triggers> 
    </Style> 
</UserControl.Resources> 

<Grid Margin="10"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="Auto" /> 
     <RowDefinition Height="*" /> 
    </Grid.RowDefinitions> 

    <StackPanel Grid.Row="0" Grid.Column="0" Margin="0 20 0 0"> 
     <StackPanel Orientation="Horizontal"> 
      <Label Content="Model Name:" Margin="0 5 2 0" Width="100" /> 
      <TextBox Text="{Binding Config.ModelName, Mode=TwoWay}" VerticalAlignment="Top" Background="WhiteSmoke" Foreground="DarkBlue" Width="200" /> 
     </StackPanel> 

     <StackPanel Orientation="Horizontal"> 
      <Label Content="Model Description:" Margin="0 5 2 0" Width="100" /> 
      <TextBox Text="{Binding Config.Description, Mode=TwoWay}" VerticalAlignment="Top" Background="WhiteSmoke" Foreground="DarkBlue" Width="600" /> 
     </StackPanel> 
    </StackPanel> 

    <TabControl Grid.Row="1" Grid.Column="0" 
       ItemsSource="{Binding Parts}" 
       ItemContainerStyle="{StaticResource TabItemContainerStyle}" 
       SelectedItem="{Binding SelectedConfigPartViewModel, Mode=TwoWay}" 
       Margin="0 40 0 0" /> 


</Grid> 

답변

1

대신에 :

<Style x:Key="TabItemContainerStyle" TargetType="{x:Type TabItem}" BasedOn="{StaticResource {x:Type TabItem}}" > 
.... 
.... 
</Style> 

을하거나 작동하지 않을 경우, 다음

변경

:

<Style x:Key="TabItemContainerStyle" TargetType="TabItem" > 
.... 
.... 
</Style> 

코드 아래에보십시오

BasedOn="{StaticResource {x:Type TabItem}}" 

BasedOn="{StaticResource NameOfYourStyleDeclaredInTheme}" 
+0

정말 고마워요, 첫 번째 옵션은 내가 그것을 원하는대로 정확하게 작동한다! 도움을 주셔서 감사합니다. –

+0

내 대답을 받아 들일 수 있도록 표시해주세요. 장래에 다른 사람을 도울 수 있습니다. – Vishal

+0

나는 그 일을하려했지만 15 점 이상의 점수 점수가 필요하다는 정보를 받았습니다. (마지막 질문 하나를 통찰력을 가질 수 있습니다 ... 원래 코드에는 두 개의 DataTemplates가 있습니다. 하나는 항목 일반 탭 항목 (TabItemHeaderTemplate 및 TabItemHeaderTemplateSelected)에 대한 다른 하나를 선택합니다 ... 이것은 하나의 글꼴을 다르게 사용하는 것 같습니다 ... 그렇지 않으면 동일합니다. IsSelected를 기반으로이 작업을 수행하는 더 좋은 방법이 있습니까? 스타일 트리거? 다시 한 번 감사드립니다. ps 그냥 체크 표시를 클릭하여 확인 된 대답으로 설정해야한다는 것을 알았습니다. 위로 화살표를 시도했습니다. –