I’m trying to define fonts which can be reference by many style elements:
<System:String x:Key="FontFamilyDefault">Arial</System:String>
<System:Int32 x:Key="FontSizeDefault">18</System:Int32>
<SolidColorBrush x:Key="FontColourDefault" Color="Black"/>
and my style refers to it by:
<Style TargetType="{x:Type Control}" x:Key="myStyle1">
<Setter Property="FontSize" Value="{StaticResource FontSizeDefault}" />
<Setter Property="FontFamily" Value="{StaticResource FontFamilyDefault}" />
<Setter Property="Foreground" Value="{StaticResource FontColourDefault}" />
</Style>
and the control refers myStyle1:
<Style TargetType="TextBox" BasedOn="{StaticResource myStyle1}" />
I get the following runtime exception:
Unable to cast object of type ‘System.String’ to type ‘System.Windows.Media.FontFamily’.
if I comment out:
<Setter Property="FontFamily" Value="{StaticResource FontFamilyDefault}
then get this exception on the size conersion:
Specified cast is not valid.
can anyone suggest how to convert string to fontfamily and how to specify the font size in xaml?
thanks in advance
You can create a StaticResource with the FontFamily type ..