I have a simply buttonStyle defined for TargetType
of Button
; but setting the style to button gives an exeption.
<Window>
<Window.Resources>
<Style x:Key="buttonStyle" TargetType="{x:Type Button}">
<Setter Property="Background" Value="Magenta"/>
</Style>
</Window.Resources>
<StackPanel Orientation="Horizontal">
<Button Content="1" FocusVisualStyle="{StaticResource buttonStyle}"/>
</StackPanel>
</Window>
Additional information: 'Button' TargetType does not match type of element 'Control'.
Further, setting the TargetType
as Control
removes the run-time error, but visual style of button doesn't change when it gets Focus
.
Style works when set as Button.Style
Edit I have two specific questions:
I agree to the fact that
FocusVisualStyle
is a property ofFrameworkElement
andFrameworkContentElement
, but why is there an error setting it on button, despite the fact that Style is a namedstyle and not a typedstyle ?Why does
FocusVisualStyle
don't get rendered on theButton
? Is theButton.FocusVisualStyle
over-ridden internally by any higher priority value like Templates, Triggers or Template Triggers ?