为什么在将动态内容添加到 ContentPresenter 时某些字体没有得到应用?
Why are some fonts not getting applied when adding dynamic content to a ContentPresenter?
我有基本的 ContentPresenter
,我要将动态内容添加到:
<ContentPresenter x:Name="Presenter"
FontSize="16"
FontFamily="Consolas" />
如果我直接在 XAML 文件中添加内容,例如
<ContentPresenter x:Name="Presenter"
FontSize="16"
FontFamily="Consolas">
<TextBlock Text="Some text" />
</ContentPresenter>
TextBlock
渲染良好,字体系列 Consolas
。
如果我在代码隐藏中动态添加内容,虽然
this.Presenter.Content = new TextBlock { Text = "Some Text" };
字体系列是系统默认字体,不是Consolas
但是
如果我使用 ContentPresenter
并将字体设置为例如 Courier New
<ContentPresenter x:Name="Presenter"
FontSize="16"
FontFamily="Courier New" />
静态和动态添加的内容呈现得非常好!
Consolas 字体不可用,请参阅此处的列表:https://msdn.microsoft.com/en-us/library/windows/apps/hh202920(v=vs.105).aspx
我有基本的 ContentPresenter
,我要将动态内容添加到:
<ContentPresenter x:Name="Presenter"
FontSize="16"
FontFamily="Consolas" />
如果我直接在 XAML 文件中添加内容,例如
<ContentPresenter x:Name="Presenter"
FontSize="16"
FontFamily="Consolas">
<TextBlock Text="Some text" />
</ContentPresenter>
TextBlock
渲染良好,字体系列 Consolas
。
如果我在代码隐藏中动态添加内容,虽然
this.Presenter.Content = new TextBlock { Text = "Some Text" };
字体系列是系统默认字体,不是Consolas
但是
如果我使用 ContentPresenter
并将字体设置为例如 Courier New
<ContentPresenter x:Name="Presenter"
FontSize="16"
FontFamily="Courier New" />
静态和动态添加的内容呈现得非常好!
Consolas 字体不可用,请参阅此处的列表:https://msdn.microsoft.com/en-us/library/windows/apps/hh202920(v=vs.105).aspx