2009-09-21 9 views

Respuesta

12

He encontrado un blog post by David Padbury de 2008 que se refiere a esto y cómo cambiarlo de código. Básicamente, usted anula las propiedades de metadatos que se fusionan en sus cambios a los valores existentes.

TextElement.FontFamilyProperty.OverrideMetadata(
typeof(TextElement), 
new FrameworkPropertyMetadata(
    new FontFamily("Comic Sans MS"))); 

TextBlock.FontFamilyProperty.OverrideMetadata(
typeof(TextBlock), 
new FrameworkPropertyMetadata(
    new FontFamily("Comic Sans MS"))); 

Hay también esta MSDN forum post que explica cómo hacerlo en XAML de dos maneras.

1) En primer lugar se define un estilo de "global" para la clase Control

<Style TargetType="{x:Type Control}"> 
    <Setter Property="FontFamily" Value="Constantia"/> 
</Style> 

y luego utilizar la propiedad BasedOn a aplicar eso a otros controles.

<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
<StackPanel.Resources> 
    <Style TargetType="{x:Type Control}" x:Key="ControlStyle"> 
    <Setter Property="FontFamily" Value="Constantia"/> 
    </Style> 

    <Style TargetType="{x:Type Label}" x:Key="LabelStyle" BasedOn="{StaticResource ControlStyle}"> 
    <Setter Property="FontWeight" Value="Bold" /> 
    </Style> 
     <Style TargetType="{x:Type Button}" x:Key="ButtonStyle" BasedOn="{StaticResource ControlStyle}"> 
     <Setter Property="Background" Value="Blue"/> 
    </Style> 
</StackPanel.Resources> 

<Label Style="{StaticResource LabelStyle}">This is a Label</Label> 
<Button Style="{StaticResource ButtonStyle}">This is a Button</Button> 
</StackPanel> 

2) Puede configurar las fuentes del sistema:

<FontFamily x:Key="{x:Static SystemFonts.MenuFontFamilyKey}">./#Segoe UI</FontFamily> 
<System:Double x:Key="{x:Static SystemFonts.MenuFontSizeKey}">11</System:Double> 
<FontWeight x:Key="{x:Static SystemFonts.MenuFontWeightKey}">Normal</FontWeight> 

aunque probablemente no recomendaría este.

3
<Application.Resources> 
    <Style x:Key="WindowStyle" TargetType="{x:Type Window}"> 
      <Setter Property="FontFamily" Value="PalatineLinoType" /> 
    </Style> 
</Application.Resources> 
Cuestiones relacionadas