2009-09-21 2 views

답변

12

저는 2008 년부터 blog post by David Padbury을 찾아 냈습니다.이 코드는 코드에서 변경하는 방법입니다. 기본적으로 변경 한 내용을 기존 값에 병합하는 메타 데이터 속성을 재정의합니다.

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

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

두 가지 방법으로 XAML에서 수행하는 방법을 설명하는 MSDN forum post도 있습니다.

1) 첫째로 당신은 Control 클래스

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

에 대해 "글로벌"스타일을 정의하고 다른 컨트롤에 그것을 적용 할 BasedOn 속성을 사용합니다.

<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) 시스템 글꼴을 설정할 수 있습니다

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

아마이 권하고 싶지 않다지만.

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