c# - UWP IoT 如何添加自定义字体
问题描述
我无法添加自定义字体。我按照此处参考此页面的步骤进行操作,但未使用该字体。
我已将字体添加到我的项目中
确实出现在我的设计师视图中
在 Windows 中打开的字体(验证字体名称):
但是当我提到它们时,它们仍然没有在我的应用程序中使用。我尝试了以下语法
<TextBlock
Grid.Column="1"
Text="{x:Bind Text}"
FontFamily="ms-appx:///Assets/Delphi-Soleto_Lt.ttf#Delphi-Soleto Light"/>
或者当我在设计师中选择字体时设计师填写它
<TextBlock
Grid.Column="1"
Text="{x:Bind Text}"
FontFamily="Delphi-Soleto Light"/>
或如本网站建议的那样
<TextBlock
Grid.Column="1"
Text="{x:Bind Text}"
FontFamily="/Assets/Delphi-Soleto_Lt.ttf#Delphi-Soleto Light"/>
非常感谢您的帮助...!
将 GIT 存储库上传到:
https://github.com/basprins/CustomFontWinIot
我正在尝试在以下位置使用 Delphi 字体BulletText.xaml
:
<TextBlock
Grid.Column="1"
Margin="0, 13, 0, 0"
Style="{StaticResource Normal}"
Text="{x:Bind Text}"
FontFamily="{StaticResource DefaultFont}"/>
我将BulletText
控件添加到主页,当应用程序启动时该控件将立即可见。
使用空白应用程序更新 git repo,该应用程序引用了不会显示的字体
在我的电脑上,我没有将字体安装到 Windows 中。我刚刚将它们添加到项目中。代码见github页面。设计器视图截图
解决方案
您不应使用FontFamily属性中的字体粗细索引来引用字体文件。如果需要设置字体粗细,可以设置TextBlock的FontWeight属性。试试这个:
<StackPanel>
<!--Don't add "Light" in the FontFamily-->
<TextBlock FontFamily="ms-appx:///Assets/Delphi-Soleto_Lt.ttf#Delphi-Soleto"
Text="Hello world, this is my test"/>
<!--Don't add "Thin" in the FontFamily-->
<TextBlock FontFamily="ms-appx:///Assets/Delphi-Soleto_Th.ttf#Delphi-Soleto"
Text="Hello world, this is my test"/>
<!--This is the default font family, set the FontWeight property-->
<TextBlock Text="Hello world, this is my test" FontWeight="Normal"/>
</StackPanel>
这是效果:
推荐阅读
- kql - Kusto KQL (Defender ATP) - 有什么方法可以按排序顺序比较字符串?
- tabulator - 列显示为行
- python - 如何调整 DataFrame 中的数据,使其匹配正确的索引日期?
- python-3.x - Binance API期货调整杠杆
- python - 无法安装 keyrings.google-artifactregistry-auth,需要 Rust?
- vb.net - 在下面的代码片段中使用列表时,AddressOf 运算符如何在 VB.net 中工作
- java - java.lang.NoClassDefFoundError: ch/qos/logback/classic/filter/ThresholdFilter
- reactjs - 使用 React 钩子来遵循 DRY 是一种好习惯吗?
- vue.js - 在 Storybook Vue 中导入节点模块
- javascript - React-Redux 操作未生效