代码之家  ›  专栏  ›  技术社区  ›  bas

UWP IoT如何添加自定义字体

  •  3
  • bas  · 技术社区  · 6 年前

    here 指的是 this page

    enter image description here

    在“我的设计器”视图中确实会显示

    enter image description here

    在Windows中打开的字体(用于验证字体名称):

    enter image description here

    <TextBlock 
        Grid.Column="1" 
        Text="{x:Bind Text}"
        FontFamily="ms-appx:///Assets/Delphi-Soleto_Lt.ttf#Delphi-Soleto Light"/>
    

    或者当我在designer中选择字体时,由设计师填写

    <TextBlock 
        Grid.Column="1" 
        Text="{x:Bind Text}"
        FontFamily="Delphi-Soleto Light"/>
    

    this site 提议

    <TextBlock 
        Grid.Column="1" 
        Text="{x:Bind Text}"
        FontFamily="/Assets/Delphi-Soleto_Lt.ttf#Delphi-Soleto Light"/>
    

    非常感谢您的帮助。。。!

    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

    在我的电脑上我做到了

    enter image description here

    3 回复  |  直到 6 年前
        1
  •  2
  •   Breeze Liu - MSFT    6 年前

    不应在中使用字体权重索引 FontFamily FontWeight 财产 TextBlock

    <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>
    

    效果如下:

    enter image description here

        2
  •  2
  •   bas    6 年前

    对其他正在拔掉头发的人的一些考虑。

    首先,这是可能的。但许多网站告诉你一个不同的故事,它使已经过于复杂的功能变得过于复杂。

    在物联网设备上可视化字体所需完成的步骤:

    将字体添加到项目中

    显然,大多数网站会告诉你的第一步。不过有几句话。

    • 不管你把字体放在哪里。它们可以位于/Assets、/Fonts、/Assets/Fonts、/Resources或您喜欢的任何位置。
    • 你不必费心 copy to output . 不管你怎么定义它。
    • Content . 这是默认的,所以你也不必为此烦恼。

    找出正确的字体名称可能会很糟糕。约定如下[fontfamily文件路径]#[font family名称]。

    例如:

    Assets/Delphi-Soleto_Lt.ttf#Delphi-Soleto
    

    <TextBlock FontFamily="Fonts/Delphi-Soleto_Lt.ttf#Delphi-Soleto" Text="This is Delphi Soleto Light" />
    

    不管您是否使用msappx语法引用路径,以下所有定义都将起作用:

    <TextBlock FontFamily="Fonts/Delphi-Soleto_Lt.ttf#Delphi-Soleto" Text="This is Delphi Soleto Light" />
    
    <TextBlock FontFamily="/Fonts/Delphi-Soleto_Lt.ttf#Delphi-Soleto" Text="This is Delphi Soleto Light" />
    
    <TextBlock FontFamily="ms-appx:///Fonts/Delphi-Soleto_Lt.ttf#Delphi-Soleto" Text="This is Delphi Soleto Light" />
    
    字体名称

    然后是大字体名。重要的是要知道,字体样式应该从字体名称中删除。例如

    • 文件“Delphi Soleto”_黑色ttf'字体名为Delphi Soleto Light的将成为Delphi Soleto
    • 文件“Delphi-Soleto A”_黑色ttf'字体名为Delphi Soleto App Black的将成为Delphi Soleto 应用程序

    dp4 font viewer 相反。

    如果打开dp4字体查看器并找到保存字体的文件夹,您将看到正确的字体名称。请注意下面屏幕截图中的字体系列名称。

    enter image description here

    验证所需字体的文本

    不是 站在我这边。最终帮助我的是,在我的目标上部署我的应用程序(在我的例子中是RPI),并在应用程序在调试器中运行时更改XAML。这些变化会立即反映在你的跑步应用程序中。

    enter image description here

    我希望这会有人在外面!特别感谢刘清风,他抽出时间来帮助我!

        3
  •  0
  •   Parsa Karami    6 年前

    应用程序xaml

    1-在项目的根目录中创建一个文件夹并命名它 “字体”

    F4层 复制到输出目录

    3英寸 应用程序xaml 文件> 应用程序资源 字典资源 标记,添加以下代码:

    <FontFamily x:Key="DefaultFont">/Fonts/(Your FontName).ttf#(Font Title)</FontFamily>
    

    <TextBlock Text="Your Sample Text" FontFamily="{StaticResource DefaultFont}"></TextBlock>
    
        4
  •  0
  •   SteffenM    4 年前

    FontFamily="/Assets/Fonts/PT_Sans/PTSans-Regular.ttf#PT Sans"
    

    如果没有前导斜杠或uri以ms appx:///开头,则默认为标准字体。在这上面扯了几根头发。

    构建操作:内容

    复制到输出目录:不复制