Reputation: 1
Screenshots:
I have a custom control with Style as
<Style TargetType="{x:Type local:IconCustom}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:IconCustom}">
<Border x:Name="border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
<Border.Style>
<Style TargetType="Border">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Red">
</Trigger>
</Style.Triggers>
</Style>
</Border.Style>
<TextBlock Text="Abcde"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
the custom control is place in CustomTest
<uc:IconCustom Width="400" Height="400" Style="{StaticResource IconButtonStyle}"/>
with a Style
<Style TargetType="{x:Type uc:IconCustom}" x:Key="IconButtonStyle">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Yellow"/>
</Trigger>
</Style.Triggers>
</Style>
here Yellow is not overriding on Red for MouseOver, why this happens, How to fix?
Tried setting Default style for MouseOver, and Style from CustomTest, it also not worked, I want if no style is given in CustomTest, then Default style (Red) will take, otherwise if Style applied in CustomTest, then Yellow will take,
Upvotes: 0
Views: 87
Reputation:
you have two problems:
Possible solution:
BasedOn="{StaticResource{x:Type local:IconCustom}}"
to IconButtonStyle, so you will just override the trigger but keep the template.The code:
<Style TargetType="{x:Type local:IconCustom}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:IconCustom}">
<Border x:Name="border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
<TextBlock Text="Abcde"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type uc:IconCustom}" x:Key="IconButtonStyle" BasedOn="{StaticResource {x:Type uc:IconCustom}}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Yellow" />
</Trigger>
</Style.Triggers>
</Style>
Default now is red, and with IconButtonStyle it's yellow.
Upvotes: 0