开发者

How do I change the default font used by Silverlight?

开发者 https://www.devze.com 2023-04-11 17:49 出处:网络
Is there any way to change the default font (Portable User Interface) used by Silverlight to a custom font without specifying a style for every single UI element? I want to avoid hav开发者_Go百科ing t

Is there any way to change the default font (Portable User Interface) used by Silverlight to a custom font without specifying a style for every single UI element? I want to avoid hav开发者_Go百科ing to explicitly set a style or bind the FontFamily it to a static resource.

I suppose I can use implicit styles, but then I have to do it for EVERY UI control type: Button, TextBlock, TextBox, etc, etc...

I wish I could just add this to my Style Dictionary (but of course it's not allowed):

<FontFamily >"TCCEB.TTF#Tw Cen MT"</FontFamily> 


If you wrap your entire application with a ContentControl and specify its FontFamily in there, as long as you don't specify the FontFamily in any of your child controls, the font should flow down to all of them.


This is what we did:

<Application.Resources>
    <FontFamily x:Key="DefaultFontFamily">/MyName.MyApp;component/Assets/segoeui.ttf#Segoe UI</FontFamily>

    <Style TargetType="Button">
        <Setter Property="FontFamily" Value="{StaticResource DefaultFontFamily}"/>
        <Setter Property="FontSize" Value="14.666"/>
    </Style>

    <Style TargetType="HyperlinkButton">
        <Setter Property="FontFamily" Value="{StaticResource DefaultFontFamily}"/>
        <Setter Property="FontSize" Value="14.666"/>
    </Style>

    ...

</Application.Resources>

Far from perfect I'm afraid.

0

精彩评论

暂无评论...
验证码 换一张
取 消