WPF应用程序使用ExpressionDark主题,希望扩展TabItem标题样式
对于使用ExpressionDark主题的WPF应用程序,我有一个TabControl,在没有任何修改的情况下,tab控件的主题样式很好 但是,当我通过样式设置器实现HeaderTemplate时,这似乎覆盖了标题模板的主题样式 我想做的是扩展主题的样式,以便我的选项卡控件的标题可以包含一个图像(在下面的示例代码中,它是硬编码的,但最终将是绑定的和动态的) 是否有方法指示TabItemHeaderTemplate或TabItemHeaderTemplateSelected项以某种方式从主题的模板执行BasedOnWPF应用程序使用ExpressionDark主题,希望扩展TabItem标题样式,wpf,xaml,themes,datatemplate,tabcontrol,Wpf,Xaml,Themes,Datatemplate,Tabcontrol,对于使用ExpressionDark主题的WPF应用程序,我有一个TabControl,在没有任何修改的情况下,tab控件的主题样式很好 但是,当我通过样式设置器实现HeaderTemplate时,这似乎覆盖了标题模板的主题样式 我想做的是扩展主题的样式,以便我的选项卡控件的标题可以包含一个图像(在下面的示例代码中,它是硬编码的,但最终将是绑定的和动态的) 是否有方法指示TabItemHeaderTemplate或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>
而不是:
<Style x:Key="TabItemContainerStyle" TargetType="TabItem" >
....
....
</Style>
到
非常感谢,第一个选项完全符合我的要求!非常感谢您的帮助。欢迎您,请将我的答案标记为已接受,以便将来对他人有所帮助。我曾尝试过这样做,但被告知我需要15分或更高的分数才能做到这一点:(最后一个问题您可能已经了解了……在我的原始代码中,我有两个数据模板,一个用于选择项时,另一个用于常规选项卡项(TabItemHeaderTemplate和TabItemHeaderTemplateSelected)…这似乎有点过火,因为一个上的字体不同…否则它们是相同的。有没有更好的方法基于IsSelected样式触发器来实现这一点?再次感谢。ps刚刚发现必须单击复选标记以设置为接受答案,我已经尝试了向上箭头。好的,我会尝试并让您知道。我已经尝试过了。但我无法回答实现它。对不起。我想你应该问另一个问题。
<Style x:Key="TabItemContainerStyle" TargetType="{x:Type TabItem}" BasedOn="{StaticResource {x:Type TabItem}}" >
....
....
</Style>
BasedOn="{StaticResource {x:Type TabItem}}"
BasedOn="{StaticResource NameOfYourStyleDeclaredInTheme}"