Как сделать так чтобы при выборе tabItem цвет его заголовка менялся
Как сделать так, чтобы при выборе TabItem цвет его заголовка менялся?
<Window x:Class="SoftPizzaHut.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SoftPizzaHut"
mc:Ignorable="d"
Title="Управление закупками PizzaHut" MinHeight="700" MinWidth="1200" FontSize="23.9"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
TextElement.FontWeight="Regular"
TextElement.FontSize="13"
TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="Auto"
Background="{DynamicResource MaterialDesignPaper}"
FontFamily="{DynamicResource MaterialDesignFont}">
<Window.Resources>
<!--Control colors.-->
<Color x:Key="WindowColor">#FFE8EDF9</Color>
<Color x:Key="GlyphColor">#FFEE3A43</Color>
<Color x:Key="DefaultBorderBrushDarkColor">Black</Color>
<Color x:Key="HeaderTopColor">#FFEE3A43</Color>
<Style TargetType="{x:Type TabControl}">
<Setter Property="OverridesDefaultStyle"
Value="True" />
<Setter Property="SnapsToDevicePixels"
Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabControl}">
<Grid KeyboardNavigation.TabNavigation="Local">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Disabled">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="Border"
Storyboard.TargetProperty="(Border.BorderBrush).
(SolidColorBrush.Color)" >
<EasingColorKeyFrame KeyTime="0"
Value="#70EFEFEF" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<TabPanel x:Name="HeaderPanel"
Grid.Row="0"
Panel.ZIndex="1"
Margin="0,0,0,0"
IsItemsHost="True"
KeyboardNavigation.TabIndex="1"
Background="Transparent" />
<Border x:Name="Border"
Grid.Row="1"
BorderThickness="1"
CornerRadius="2"
KeyboardNavigation.TabNavigation="Local"
KeyboardNavigation.DirectionalNavigation="Contained"
KeyboardNavigation.TabIndex="2">
<ContentPresenter x:Name="PART_SelectedContentHost"
Margin="4"
ContentSource="SelectedContent" />
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type TabItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Grid x:Name="Root">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="SelectionStates">
<VisualState x:Name="Unselected" />
<VisualState x:Name="Selected">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="Border"
Storyboard.TargetProperty="(Panel.Background).
(GradientBrush.GradientStops)[3].(GradientStop.Color)">
<EasingColorKeyFrame KeyTime="0"
Value="#66FF000D" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border x:Name="Border"
Margin="0,0,0,0"
BorderThickness="0,0,0,0"
CornerRadius="0,0,0,0">
<Border.BorderBrush>
<SolidColorBrush Color="#0001FB11" />
</Border.BorderBrush>
<Border.Background>
<LinearGradientBrush StartPoint="0,0"
EndPoint="0,1">
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#1C211AA9"
Offset="0.907" />
<GradientStop Color="#FFEE3A43" Offset="1"/>
<GradientStop Color="#FFEE3A43" Offset="0.907"/>
<GradientStop Color="#26FF0000" Offset="0.903"/>
<GradientStop Color="#00F7418C" Offset="0.667"/>
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Border.Background>
<ContentPresenter x:Name="ContentSite"
VerticalAlignment="Center"
HorizontalAlignment="Center"
ContentSource="Header"
Margin="12,2,12,2"
RecognizesAccessKey="True" />
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<SolidColorBrush x:Key="pizzastyle1" Color="#FFA71732"/>
<SolidColorBrush x:Key="pizzastyle2" Color="#FFE20029"/>
<SolidColorBrush x:Key="TextBox.Static.Border" Color="#FFABAdB3"/>
<SolidColorBrush x:Key="TextBox.MouseOver.Border" Color="#FF7EB4EA"/>
<SolidColorBrush x:Key="TextBox.Focus.Border" Color="#FF569DE5"/>
<Style x:Key="search" TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
<Setter Property="BorderBrush" Value="{StaticResource TextBox.Static.Border}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="AllowDrop" Value="true"/>
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Border x:Name="border" CornerRadius="5" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True">
<ScrollViewer x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Opacity" TargetName="border" Value="0.56"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox.MouseOver.Border}"/>
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="true">
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox.Focus.Border}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsInactiveSelectionHighlightEnabled" Value="true"/>
<Condition Property="IsSelectionActive" Value="false"/>
</MultiTrigger.Conditions>
<Setter Property="SelectionBrush" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}"/>
</MultiTrigger>
</Style.Triggers>
</Style>
<SolidColorBrush x:Key="OpacityGrey" Color="#FFBDBDBD"/>
</Window.Resources>
<Grid Margin="0,0,0,-34">
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="833*"/>
<ColumnDefinition Width="367*"/>
</Grid.ColumnDefinitions>
<Image Margin="0,24,27,0" Source="/PizzaHut.svg.png" MinWidth="15" MaxWidth="150" MinHeight="50" MaxHeight="300" Stretch="Uniform" StretchDirection="Both" Grid.IsSharedSizeScope="True" HorizontalAlignment="Right" Width="157" Height="141" VerticalAlignment="Top" Grid.Column="1"/>
<TabControl Margin="0,75,10,10" FontSize="20" Grid.ColumnSpan="2" >
<TabItem Header="Закупки" BorderBrush="{x:Null}" Background="{x:Null}">
<Grid/>
</TabItem>
<TabItem Header="Поставщики" BorderBrush="{x:Null}" Background="{x:Null}">
<Grid/>
</TabItem>
<TabItem Header="Товары" BorderBrush="{x:Null}" Background="{x:Null}">
<Grid/>
</TabItem>
</TabControl>
<Expander Height="29" Header="Расширенный поиск" Margin="0,31,42,0" VerticalAlignment="Top" Background="#00000000" FontSize="20" Panel.ZIndex="1111" Padding="0,0,0,0" HorizontalAlignment="Right" Width="244" FlowDirection="RightToLeft" FontWeight="Normal">
<Expander.Foreground>
<SolidColorBrush Color="#FFEE3A43"/>
</Expander.Foreground>
<Grid Background="#8CE4E4E4" Margin="0,10,-540,-230" Width="783" HorizontalAlignment="Left">
<TextBox HorizontalAlignment="Left" Margin="10,51,0,0" TextWrapping="Wrap" Text="Поставщик" VerticalAlignment="Top" Width="407"/>
<TextBox HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="Название товара" VerticalAlignment="Top" Width="407" Height="36"/>
<TextBox HorizontalAlignment="Left" Margin="10,124,0,0" TextWrapping="Wrap" Text="Категория" VerticalAlignment="Top" Width="407"/>
<TextBox HorizontalAlignment="Left" Margin="161,174,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
<TextBox HorizontalAlignment="Left" Margin="10,174,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
<Label Content="Цена От:" HorizontalAlignment="Left" Margin="281,166,0,0" VerticalAlignment="Top" Height="44" Width="136" FlowDirection="LeftToRight"/>
</Grid>
</Expander>
<TextBox x:Name="TextBox1" Style="{DynamicResource search}" Margin="16,24,32,0" TextWrapping="NoWrap" VerticalAlignment="Top" MinWidth="485" Foreground="{DynamicResource OpacityGrey}" Padding="15,4,245,4" BorderThickness="1,1,1,1" SnapsToDevicePixels="True" BorderBrush="#A8ABADB3" Text="Поиск" LostKeyboardFocus="TextBox1_LostKeyboardFocus" GotKeyboardFocus="TextBox1_GotKeyboardFocus" Height="42"/>
<Button Content="Найти" Margin="67,27,216,659" Grid.Column="1"/>
</Grid>
Ответы (1 шт):
Автор решения: Данил Струченков
→ Ссылка
Если я правильно понял вы работаете с WPF. Там при нажатии на элемент правой кнопкой мыши , появляется окно в котором можно править копию шаблона , а потом в нужный элемент подставить этот шаблон , ниже я привел пример кода в котором поменял цвет при наведении
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" TargetName="Bd" Value="red"/>
<Setter Property="Foreground" Value="#3EA0FE"/>
</Trigger>
А Так же там есть код при нажатии на вкладку
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Red"/>
<Setter Property="Foreground" Value="#3E68FE"/>
<Setter Property="BorderBrush" Value="ForestGreen"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="FontSize" Value="16"/>
</Trigger>
Вот так я подставил свой шаблон
<TabItem Style="{DynamicResource TabItemStyle1}" Margin="49,-2,-60,-1">
</TabItem>
Как создать копию шаблона!
Полностью весь шаблон
<Style x:Key="TabItemStyle1" TargetType="{x:Type TabItem}">
<Setter Property="Foreground" Value="White"/>
<Setter Property="Padding" Value="6,1,6,1"/>
<Setter Property="Opacity" Value="1"/>
<Setter Property="TextElement.Foreground" Value="#797B8E"/>
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="FontSize" Value="14"/>
<Setter Property="Background" Value="{x:Null}"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Grid SnapsToDevicePixels="true">
<Border x:Name="Bd" Background="{TemplateBinding Background}" CornerRadius="4" Padding="{TemplateBinding Padding}" >
<ContentPresenter x:Name="Content" ContentSource="Header" HorizontalAlignment="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" TargetName="Bd" Value="red"/>
<Setter Property="Foreground" Value="#3EA0FE"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="false"/>
<Condition Property="IsMouseOver" Value="true"/>
</MultiTrigger.Conditions>
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="true"/>
<Condition Property="TabStripPlacement" Value="Top"/>
</MultiTrigger.Conditions>
<Setter Property="Margin" Value="-2,-2,-2,-1"/>
<Setter Property="Margin" TargetName="Content" Value="0,0,0,1"/>
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="true"/>
<Condition Property="TabStripPlacement" Value="Bottom"/>
</MultiTrigger.Conditions>
<Setter Property="Margin" Value="-2,-1,-2,-2"/>
<Setter Property="Margin" TargetName="Content" Value="0,1,0,0"/>
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="true"/>
<Condition Property="TabStripPlacement" Value="Left"/>
</MultiTrigger.Conditions>
<Setter Property="Margin" Value="-2,-2,-1,-2"/>
<Setter Property="Margin" TargetName="Content" Value="0,0,1,0"/>
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="true"/>
<Condition Property="TabStripPlacement" Value="Right"/>
</MultiTrigger.Conditions>
<Setter Property="Margin" Value="-1,-2,-2,-2"/>
<Setter Property="Margin" TargetName="Content" Value="1,0,0,0"/>
</MultiTrigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Opacity" TargetName="Bd" Value="0.6"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Red"/>
<Setter Property="Foreground" Value="#3E68FE"/>
<Setter Property="BorderBrush" Value="ForestGreen"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="FontSize" Value="16"/>
</Trigger>
</Style.Triggers>
</Style>
