简体   繁体   English

将动态内容添加到ContentPresenter时,为什么没有应用某些字体?

[英]Why are some fonts not getting applied when adding dynamic content to a ContentPresenter?

I have basic ContentPresenter that I'm adding dynamic content to: 我有基本的ContentPresenter ,我要将动态内容添加到:

<ContentPresenter x:Name="Presenter"
                  FontSize="16"
                  FontFamily="Consolas" />

If I'm adding content directly in the XAML file, like 如果我直接在XAML文件中添加内容,例如

<ContentPresenter x:Name="Presenter"
                  FontSize="16"
                  FontFamily="Consolas">
    <TextBlock Text="Some text" />
</ContentPresenter>

The TextBlock renders fine, with the font family Consolas . TextBlock使用字体系列Consolas很好地呈现。

If I add content dynamically in the code-behind, though 如果我在后面的代码中动态添加内容

this.Presenter.Content = new TextBlock { Text = "Some Text" };

the font family is the default font of the system and not Consolas 字体系列是系统的默认字体,而不是Consolas

BUT

If I use a ContentPresenter with the font set to eg Courier New 如果我使用ContentPresenter并将字体设置为例如Courier New

<ContentPresenter x:Name="Presenter"
                  FontSize="16"
                  FontFamily="Courier New" />

static and dynamically added content is rendered perfectly fine! 静态动态添加的内容呈现完美!

Consolas字体不可用,请参见此处的列表: https : //msdn.microsoft.com/zh-cn/library/windows/apps/hh202920(v= vs.105).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM