简体   繁体   中英

Override FontFamily

I have set a FontFamily in my ResourceDictionary

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

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

or, if I only want to change the FontFamily for the ComboBox, I can override the 'ComboBoxFontFamily'.

So how am I able to reference the RegularFontFamily from within the Theme?

You cannot reference a FontFamily from another FontFamily and, also, you cannot change the family name of a FontFamily after it has been constructed.

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.

But there is no kind of binding option or similar available that you can use in XAML.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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