Wie kann ich die FontFamily und FontSize für die Anwendung in App.xaml festlegen?Set FontFamily und FontSize für die Anwendung in App.xaml
10
A
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
- 1. C# set FontSize von TextBox
- 2. WPF Label FontSize und FontFamily im Designer korrekt, aber zur Laufzeit falsch
- 3. jQuery set fontsize bei Wertänderung Seltsames Verhalten
- 4. Anzeigen von FontFamily in Combobox
- 5. fontSize funktionieren nicht richtig
- 6. gespalten app.xaml Stile in Dateien
- 7. Override Standard Theme in App.xaml
- 8. Get Font Name von FontFamily in WPF
- 9. WPF Richtextbox FontFace/FontSize
- 10. Dynamisch Set Taskbar Icon für Windows-Anwendung
- 11. Wie ändere ich die FontFamily auf einem ContentPresenter?
- 12. Set Ablaufdatum der Anwendung
- 13. TextView FontSize nach unterschiedlicher Auflösung und ScreenSize
- 14. WPF-Anwendung, die nicht debuggt
- 15. Set Charset in Schienen-Anwendung
- 16. Wie wird die Standardschrift für eine WPF-Anwendung festgelegt?
- 17. Set Hintergrund meiner Anwendung
- 18. Was ist der Unterschied zwischen fontFamily und typeFace in Android?
- 19. App.XAML wo bist du?
- 20. FontSize für hovered Element in WPF erhöhen ListBox
- 21. WPF TextBlock FontStyle = "Kursiv" FontFamily = "Segoe UI Light"
- 22. Fontfamily funktioniert nicht auf Android Lollipop
- 23. Set Spaltenname für die Größe()
- 24. Zugriff auf die in app.xaml definierte Ressource nicht möglich
- 25. Programatically die Umwelt Version Set für RollbarSharp
- 26. Set reportviwer's Parameter in einer Anwendung
- 27. App.xaml Stil kann nicht in Usercontrol verwendet werden, wie kommt es?
- 28. Set Segoe UI Symbol Schriftart programmgesteuert
- 29. Wie bekomme ich diese XAML von app.xaml
- 30. WPF - Binding FontFamily von TextBox zu einer ComboBox