如何在 WPF 中使用 Segoe MDL2 Assets 字体以编程方式创建文本块 [英] How to programmatically create textblock using Segoe MDL2 Assets Font in WPF

查看:24
本文介绍了如何在 WPF 中使用 Segoe MDL2 Assets 字体以编程方式创建文本块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这应该很容易,但我得到的不是我需要的图标,而是一堆方框.

I guess this should be easy, but instead of the icon I require, I get a bunch of square boxes.

最初我是在 xaml 中硬编码菜单:

Originally I was hard coding a menu in xaml:

code omitted
<ListBoxItem Name="menuHome" >
<StackPanel Orientation="Horizontal">
    <TextBlock FontFamily="Segoe MDL2 Assets" Text="&#xE10F;" FontSize="16" VerticalAlignment="Center" />
    <TextBlock Text="Home" FontSize="16" VerticalAlignment="Center" Padding="15,0,0,0"/>
</StackPanel>
</ListBoxItem>
code omitted

我现在必须动态创建这个菜单,所以我有以下内容:

I now have to dynamically create this menu so I have the following:

ListBoxItem menuHome = new ListBoxItem();
StackPanel menuHomeStackPanel = new StackPanel() { Orientation = Orientation.Horizontal };
menuHomeStackPanel.Children.Add(new TextBlock() { FontFamily = new FontFamily("Segoe MDL2 Assets"), FontSize = 16, VerticalAlignment = VerticalAlignment.Center, Text = "&#xE10F;" });
menuHomeStackPanel.Children.Add(new TextBlock() { FontSize = 16, VerticalAlignment = VerticalAlignment.Center, Text = "Home", Padding = new Thickness(15, 0, 0, 0) });
menuHome.Content = menuHomeStackPanel;
menuHome.Name = "menuHome";
IconsListBox.Items.Add(menuHome);

除了 Segoe MDL2 Assets 字体(可以在下面的屏幕截图中看到)之外,这几乎给了我相同的效果:

This almost gives me the same except for the Segoe MDL2 Assets font which can be seen in the screenshot below:

任何想法 - 可能很简单......?

Any ideas - probably simple...?

推荐答案

试试这个:

Text = "\xE10F" 

这篇关于如何在 WPF 中使用 Segoe MDL2 Assets 字体以编程方式创建文本块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆