Unfortunately, you cannot apply styles to the base type FrameworkElement; while WPF allows you to write a style, it will not apply to the controls that flow from it. Apparently, this also applies to FrameworkElement subtypes, for example. ButtonBase, supertype Button / ToggleButton / RepeatButton.
You can still use inheritance, but you have to use the explicit BasedOn syntax to apply it to the types of control you want to apply to.
<Window.Resources> <Style TargetType="{x:Type FrameworkElement}"> <Setter Property="Margin" Value="10" /> </Style> <Style TargetType="{x:Type Label}" BasedOn="{StaticResource {x:Type FrameworkElement}}" /> <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type FrameworkElement}}" /> <Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type FrameworkElement}}" /> </Window.Resources>
Nicholas Armstrong Jun 22 '09 at 13:28 2009-06-22 13:28
source share