There is a basic style that applies to all buttons. I inherit from it another style that will be used only in one button. But then this style interrupts the base one and applies to all buttons.
Is it possible to somehow specify the TargetType
property in the derived style so that it does not point to any of the types, or do you have to remove this property from the basic style and explicitly prescribe it for each button?
Basic style:
<Style x:Key="GeneralButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}"> <Setter Property="Background" Value="Black" /> <Setter Property="MinHeight" Value="15" /> <Setter Property="MinWidth" Value="30" /> <Setter Property="MaxHeight" Value="150" /> <Setter Property="MaxWidth" Value="300" /> <Setter Property="Foreground" Value="Black" /> <Setter Property="Margin" Value="0" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Grid> <Rectangle Name="GelBackground" RadiusX="0" RadiusY="0" Fill="#FFB2B2B2"/> <Rectangle Name="GelShine" Margin="1,1,1,1" RadiusX="0" RadiusY="0"> <Rectangle.Fill> <LinearGradientBrush StartPoint="0,0" EndPoint="0,2"> <GradientStop Offset="0.3" Color="#ccffffff" /> <GradientStop Offset="0.6" Color="Transparent" /> </LinearGradientBrush> </Rectangle.Fill> </Rectangle> <ContentPresenter Name="GelButtonContent" VerticalAlignment="Center" HorizontalAlignment="Center" Content="{TemplateBinding Content}" /> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Rectangle.Fill" TargetName="GelBackground"> <Setter.Value> <RadialGradientBrush> <GradientStop Offset="0" Color="#FF4885CD" /> <GradientStop Offset="1" Color="#FF1B5FF0" /> </RadialGradientBrush> </Setter.Value> </Setter> <Setter Property="Foreground" Value="Black" /> </Trigger> <Trigger Property="IsPressed" Value="True"> <Setter Property="Rectangle.Fill" TargetName="GelBackground"> <Setter.Value> <RadialGradientBrush> <GradientStop Offset="0" Color="#FFFFD39F" /> <GradientStop Offset="1" Color="#FFFF9C00" /> </RadialGradientBrush> </Setter.Value> </Setter> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>
Derivative:
<Style x:Key="SearchButtonStyle" BasedOn="{StaticResource GeneralButtonStyle}" > <Setter Property="Control.Tag" Value="1"></Setter> <Style.Triggers> <Trigger Property="Control.Tag" Value="0"> <Setter Property="Button.Content" Value="Остановить поиск"></Setter> </Trigger> <Trigger Property="Control.Tag" Value="1"> <Setter Property="Button.Content" Value="Найти приложения"></Setter> </Trigger> </Style.Triggers> </Style>
x:Key
, then it will not apply to all by default. And who needs it, just specify with reference to the key. - Monk