如何向WindowsTemplate Studio(WPF)项目添加自定义字体?
字体放在自己的文件夹中,这就是我的App.xaml代码:
<Application
x:Class="Creator.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="OnStartup"
Exit="OnExit"
DispatcherUnhandledException="OnDispatcherUnhandledException">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Styles/_FontSizes.xaml" />
<ResourceDictionary Source="/Styles/_Thickness.xaml" />
<ResourceDictionary Source="/Styles/MetroWindow.xaml" />
<ResourceDictionary Source="/Styles/TextBlock.xaml" />
<!--
MahApps.Metro resource dictionaries.
Learn more about using MahApps.Metro at https://mahapps.com/
-->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<!-- Accent and AppTheme setting -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Blue.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
谢谢!
1条答案
按热度按时间q8l4jmvw1#
我已经知道它是如何为我工作的:
1.将字体添加到“Fonts”文件夹
1.在代码中使用字体:
FontFamily="pack://application:,,,/Fonts/#password"
TextBox.FontFamily = new FontFamily(new Uri("pack://application:,,,/"), "./Fonts/#password");