What's Wrong With This Style?
-
I'm creating a theme with a base style for all controls:
<FontFamily x:Key="Font.Family.Default">Segoe UI</FontFamily>
<sys:Double x:Key="Font.Size.Header1">18</sys:Double>
<sys:Double x:Key="Font.Size.Header2">16</sys:Double>
<sys:Double x:Key="Font.Size.Header3">14</sys:Double>
<sys:Double x:Key="Font.Size.Normal">12</sys:Double><SolidColorBrush x:Key="TextBlock.Static.Background" Color="Transparent"/>
<SolidColorBrush x:Key="TextBlock.Static.Foreground" Color="DarkGray"/><Style x:Key="ControlBase" TargetType="{x:Type Control}">
<Setter Property="Control.FontSize" Value="{StaticResource Font.Size.Normal}"/> <Setter Property="Control.FontFamily" Value="{StaticResource Font.Family.Default}"/> <Setter Property="Control.HorizontalAlignment" Value="Center"/> <Setter Property="Control.VerticalAlignment" Value="Center"/>
</Style>
<Style TargetType="{x:Type TextBlock}"
BasedOn="{StaticResource ControlBase}"><Setter Property="Background" Value="{StaticResource TextBlock.Static.Background}"/> <Setter Property="Foreground" Value="{StaticResource TextBlock.Static.Foreground}"/>
</Style>
I'm trying to use it like this:
<TextBlock Grid.Row="0"
Grid.Column="0"
Text="Test"
Margin="22,0,0,0"/>The designer wont load, and when I run it I get
System.Windows.Markup.XamlParseException
Message='Initialization of 'System.Windows.Controls.TextBlock' threw an exception.' Line number '56' and line position '20'.Inner Exception 1: InvalidOperationException: Can only base on a Style with target type that is base type 'TextBlock'.
What's wrong here??
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
-
I'm creating a theme with a base style for all controls:
<FontFamily x:Key="Font.Family.Default">Segoe UI</FontFamily>
<sys:Double x:Key="Font.Size.Header1">18</sys:Double>
<sys:Double x:Key="Font.Size.Header2">16</sys:Double>
<sys:Double x:Key="Font.Size.Header3">14</sys:Double>
<sys:Double x:Key="Font.Size.Normal">12</sys:Double><SolidColorBrush x:Key="TextBlock.Static.Background" Color="Transparent"/>
<SolidColorBrush x:Key="TextBlock.Static.Foreground" Color="DarkGray"/><Style x:Key="ControlBase" TargetType="{x:Type Control}">
<Setter Property="Control.FontSize" Value="{StaticResource Font.Size.Normal}"/> <Setter Property="Control.FontFamily" Value="{StaticResource Font.Family.Default}"/> <Setter Property="Control.HorizontalAlignment" Value="Center"/> <Setter Property="Control.VerticalAlignment" Value="Center"/>
</Style>
<Style TargetType="{x:Type TextBlock}"
BasedOn="{StaticResource ControlBase}"><Setter Property="Background" Value="{StaticResource TextBlock.Static.Background}"/> <Setter Property="Foreground" Value="{StaticResource TextBlock.Static.Foreground}"/>
</Style>
I'm trying to use it like this:
<TextBlock Grid.Row="0"
Grid.Column="0"
Text="Test"
Margin="22,0,0,0"/>The designer wont load, and when I run it I get
System.Windows.Markup.XamlParseException
Message='Initialization of 'System.Windows.Controls.TextBlock' threw an exception.' Line number '56' and line position '20'.Inner Exception 1: InvalidOperationException: Can only base on a Style with target type that is base type 'TextBlock'.
What's wrong here??
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
TextBlock doesn't inherit from class Control.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
-
TextBlock doesn't inherit from class Control.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
LOL - I knew that. Wow, I need to take a break. Thanks
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.