2009-09-21 17 views

Antwort

12

Ich habe eine blog post by David Padbury von 2008 gefunden, die in diese geht und wie man es vom Code ändert. Grundsätzlich überschreiben Sie die Metadateneigenschaften, die in Ihren Änderungen mit den vorhandenen Werten zusammengeführt werden.

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

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

Es gibt auch diese MSDN forum post, die erklärt, wie es auf zwei Arten in XAML zu tun. Zum einem

1) definieren Sie einen „globalen“ Stil für die Control Klasse

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

und dann die BasedOn Eigenschaft, dass auf andere Steuerelemente.

<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) Sie können die System-Fonts eingestellt:

<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> 

Obwohl ich würde wahrscheinlich nicht empfehlen.

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