'Why the following WPF style is not applied?
Why doesn't the following style work? I have in other places the exact same construct with different controls and it works.
Using TargetType="{x:Type Separator}"
instead of TargetType="Separator"
doesn't work either. Neither moving Style
upper in the XAML hierarchy. Can I avoid using x:Key="styleName"
and Style="{StaticResource styleName}"
?
But more importantly I'm trying to understand why such a style binding doesn't work always.
<ToolBar Height="25">
<ToolBar.Resources>
<Style TargetType="Separator">
<Setter Property="Margin" Value="15"/>
</Style>
<Style TargetType="RadioButton">
<Setter Property="Margin" Value="10"/>
<Setter Property="Width" Value="50"/>
</Style>
</ToolBar.Resources>
<RadioButton Content="A"/> <!-- NOT APPLIED HERE -->
<Separator/> <!-- NOT APPLIED HERE -->
<RadioButton Content="B"/> <!-- NOT APPLIED HERE -->
</ToolBar>
Solution 1:[1]
WPF's Toolbar does some funky things with its child controls. Unlike other containers, it's not as simple as defining a style that applies to a type.
Have a look at this blog post for some information that might help. Styling controls on a ToolBar.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Glorfindel |