I want to create multiple styles in the Window.Resources. Below is the code I tried, but it’s not working:
<Window.Resources>
<Style x:Key="StyleOne" TargetType="{x:Type Control}">
<Setter Property="Control.Background" Value="Blue"></Setter>
<Setter Property="Control.Height" Value="20"></Setter>
</Style>
<Style x:Key="StyleTwo" BasedOn="{StaticResource StyleOne}">
<Setter Property="Control.Background" Value="Red"></Setter>
<Setter Property="Control.Height" Value="20"></Setter>
</Style>
</Window.Resources>
<Button Style="{StaticResource StyleOne}"></Button>
<Button Style="{StaticResource StyleTwo}"></Button>
It throws an error saying:
The property “Content” is set more than once.
This error has nothing to do with styles, the window can only contain one child (which sets the
Content), use some container which can contain more than one child. e.g. aStackPanelorGrid.(See also: Panels Overview)