Good day, Lord. There was a need to make SearchBox. The essence of the question is as follows: TextBox + Button I put in the UserControl. When you hover the mouse over the UserControl, you need to change the Background / Foreground of this UserControl and accordingly make my TextBox and button change to these values. I implemented this task. Here is the code:
<UserControl x:Class="PTRCPriceCalculator.SearchBox" 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" xmlns:local="clr-namespace:PTRCPriceCalculator" mc:Ignorable="d" Style="{StaticResource UserControlStyle}" d:DesignHeight="40" d:DesignWidth="300"> <UserControl.Template> <ControlTemplate TargetType="{x:Type UserControl}"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="40"/> </Grid.ColumnDefinitions> <TextBox Grid.Column="0" Style="{StaticResource DarkTextBox}" Background="{TemplateBinding Background}" Foreground="{TemplateBinding Foreground}" Text="Search..."/> <Button Grid.Column="1" Style="{StaticResource InnerSearchButton}" Background="{TemplateBinding Background}" Foreground="{TemplateBinding Foreground}"/> </Grid> </ControlTemplate> </UserControl.Template> </UserControl> Here is the UserControl style:
<Style TargetType="{x:Type UserControl}" x:Key="UserControlStyle"> <Setter Property="Background" Value="{StaticResource BackgroundMediumDarkBrush}"/> <Setter Property="Foreground" Value="{StaticResource ForegroundLightBrush}"/> <Style.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter Property="Background" Value="{StaticResource BackgroundDarkBrush}"/> <Setter Property="Foreground" Value="{StaticResource ForegroundVeryLightBrush}"/> </Trigger> </Style.Triggers> </Style> And the question is that it is necessary for me that if the user directs the mouse specifically on the button, then she has to change the properties of the Background / Foreground differently, uniquely. But the fact is that my UserControl trigger overrides the button trigger, and accordingly when I click the button with the mouse, nothing unique happens.
Do not tell me how to solve the problem?
Here is the style of the InnerSearchButton:
<Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}"> <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="{TemplateBinding Content}"/> </Border> </ControlTemplate> </Setter.Value> </Setter> <Style.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter Property="Background" Value="{StaticResource BackgroundVeryDarkBrush}"/> <Setter Property="Foreground" Value="Red"/> </Trigger> </Style.Triggers>
InnerSearchButton. - VladD