Gra*_* H. 6 c# silverlight xaml
我正在试图弄清楚如何在我的App.xaml中设置一个FontFamily,以便我可以在任何需要的地方以声明方式应用该样式.在ResourceDictionary我可以应用类似的东西:
<System:Double x:Key="SmallTextSize">10</System:Double>
Run Code Online (Sandbox Code Playgroud)
那我想做的是:
<FontFamily x:Key="MainFont">Wingdings</FontFamily>
Run Code Online (Sandbox Code Playgroud)
但是,我唯一可以工作的是隐式样式,它需要一个目标,以及我想要使用的字体的多个声明.我需要能够将我最终使用的样式应用于任何控件的FontFamily属性.
这是我目前最接近的地方:
<System:String x:Key="MainFont">Wingdings</System:String>
<Style TargetType="UserControl">
<Setter Property="FontFamily" Value="{StaticResource MainFont}"></Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
这个实现不适用于像是因为它期望MainFont是FontFamily而不是字符串:
<TextBlock Text="{Binding}" Margin="0,0,0,4" FontWeight="Normal" FontFamily="{StaticResource MainFont}" FontSize="14.667" />
Run Code Online (Sandbox Code Playgroud)
我该怎么处理?谢谢!
Chr*_* W. 12
不确定我完全理解这个,因为我所做的是;
<FontFamily x:Key="MainFont">WingDings</FontFamily>
Run Code Online (Sandbox Code Playgroud)
如果您正在谈论然后将其应用于多个实例而不必向每个实例声明它,那么我就会这样做;
<Object>
<Object.Resources>
<Style TargetType="TextBlock" BasedOn="{StaticResource YourDefaultTextBlockStyleToInheritOtherProperties}">
<Setter Property="FontFamily" Value="{StaticResource MainFont}"/>
</Style>
</Object.Resources>
<!-- Your FontFamily automatically gets inherited to all children of the object
whether your object is say a Grid, or StackPanel,
or even an entire UserControl -->
<TextBlock Text="ABCDEFG"/>
<TextBlock Text="12345"/>
<TextBlock Text="!()*&@#"/>
</Object>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9929 次 |
| 最近记录: |