Skip to content

Setting FontFamily at runtime (custom font)? #17199

Answered by stevemonaco
kuiperzone asked this question in Q&A
Discussion options

You must be logged in to vote

Ah, good to know. Thanks!

For anybody following along, this is possible today (fixing my example above):

var fc = new EmbeddedFontCollection(new Uri("fonts:App", UriKind.Absolute), new Uri(@"avares://AvaloniaApplication25/Assets", UriKind.Absolute));
FontManager.Current.AddFontCollection(fc);

text.FontFamily = new FontFamily("fonts:App#Nunito");

It leaks a bit of font storage knowledge vs simply "Nunito", so I do wish any added FontCollections would be searched before the default font is used, but I might be bikeshedding.

I still prefer the static class approach if your entire set of custom fonts is known at compile-time and come from resources.

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@stevemonaco
Comment options

@Gillibald
Comment options

@kuiperzone
Comment options

@stevemonaco
Comment options

Answer selected by kuiperzone
@kuiperzone
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants