如何在WPF项目中添加自定义字体?
如何将自定义字体添加到我的WindowStem Plate 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>
谢谢!
How is it possible to add a custom font to my WindowsTemplate Studio (WPF) project?
The font is placed in a own folder and that's my App.xaml code:
<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>
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经发现了它是如何工作的:
将您的字体添加到“字体”文件夹
yourfont.ttf(右键单击) - &gt;属性:
fontfamily =“ pack://应用程序:,,/fonts/#password”
textbox.fontfamily = new fontfamily(new Uri(“ pack:// application:,,/”),“ ./fonts/#password”);
>I have already found out how it works for me:
Add your font to a "Fonts" folder
yourFont.ttf (right click) -> Properties:
FontFamily="pack://application:,,,/Fonts/#password"
TextBox.FontFamily = new FontFamily(new Uri("pack://application:,,,/"), "./Fonts/#password");