如何向我的 WindowsTemplate Studio (WPF) 專案添加自定義字體?
字體放置在自己的檔案夾中,這是我的 App.xaml 代碼:
<Application
x:Class="DicomCameraConfigurationCreator.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>
謝謝!
uj5u.com熱心網友回復:
我已經發現它對我有用:
將字體添加到“字體”檔案夾
yourFont.ttf(右鍵單擊)-> 屬性:
- 構建動作 -> 資源
- 復制到輸出目錄 -> 不復制
- 在代碼中使用字體:
- xml->
FontFamily="pack://application:,,,/Fonts/#password" - c#代碼后面->
TextBox.FontFamily = new FontFamily(new Uri("pack://application:,,,/"), "./Fonts/#password");
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/471395.html
