简体   繁体   English

覆盖字体族

[英]Override FontFamily

I have set a FontFamily in my ResourceDictionary我在我的 ResourceDictionary 中设置了一个 FontFamily

<FontFamily x:Key="RegularFontFamily">Segoe UI Regular</FontFamily>

and I have set a Theme for Buttons, CHeckBoxes, Labels, etc, where I want to adapt that FontFamily and make it overridable我已经为按钮、复选框、标签等设置了一个主题,我想在其中调整该 FontFamily 并使其可覆盖

<FontFamily x:Key="ComboBoxFontFamily">This is where I want to reference the RegularFontFamily</FontFamily>

And with this approach, I can override the RegularFontFamily within the app.xaml :通过这种方法,我可以覆盖 app.xaml 中的app.xaml

<FontFamily x:Key="RegularFontFamily">Arial</FontFamily>

or, if I only want to change the FontFamily for the ComboBox, I can override the 'ComboBoxFontFamily'.或者,如果我只想更改 ComboBox 的 FontFamily,我可以覆盖“ComboBoxFontFamily”。

So how am I able to reference the RegularFontFamily from within the Theme?那么我如何才能从主题中引用RegularFontFamily呢?

You cannot reference a FontFamily from another FontFamily and, also, you cannot change the family name of a FontFamily after it has been constructed.您不能从另一个FontFamily引用FontFamily ,而且在构造FontFamily后,您也不能更改其姓氏。

The solution to your issue is either to set the themed font directly:您的问题的解决方案是直接设置主题字体:

<FontFamily x:Key="ComboBoxFontFamily">Segoe UI Regular</FontFamily>

...or to programmatically get the "RegularFontFamily" resource and replace your "ComboBoxFontFamily" resource with it at runtime. ...或以编程方式获取“RegularFontFamily”资源并在运行时用它替换您的“ComboBoxFontFamily”资源。

But there is no kind of binding option or similar available that you can use in XAML.但是在 XAML 中没有可用的绑定选项或类似选项。

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

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