App.xaml でアプリケーションの FontFamily と FontSize を設定するにはどうすればよいですか?
33041 次
2 に答える
13
2008 年の 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 で 2 つの方法でそれを行う方法を説明するこのMSDN フォーラムの投稿もあります。
Controlまず、クラスの「グローバル」スタイルを定義します
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>
システム フォントを設定できます。
./#Segoe UI <System:Double x:Key="{x:Static SystemFonts.MenuFontSizeKey}">11</System:Double> 通常
私はおそらくこれをお勧めしませんが。
于 2009-09-21T08:28:54.267 に答える
3
<Application.Resources>
<Style x:Key="WindowStyle" TargetType="{x:Type Window}">
<Setter Property="FontFamily" Value="PalatineLinoType" />
</Style>
</Application.Resources>
于 2011-02-05T17:13:04.407 に答える