When WPF using UWP, Could we set Microsoft.UI.Xaml.Media.FontFamily by C# code?

GuoLearn 251 Reputation points
2021-09-03T01:31:34.143+00:00

this XAML can set fontFamily :
<FontFamily>fontFamilyName[,fallbackFontFamilyName]*</FontFamily>

  • or -
    <object FontFamily="fontFamilyName[,fallbackFontFamilyName]" ... />
    -or-
    <object FontFamily="[uri]fontFamilyName[,[uri]fallbackFontFamilyName]
    " ... />
    -or-
    <object FontFamily="embeddedUri#fontFamilyName[,[uri]fallbackFontFamilyName]*" ... />

Can we set the fontFamily by C# code ,like
FontFamily= new FontFamily(new Uri(@"C:\fontFamilyName").AbsoluteUri) ?
i try it but it do not work。
Could you tell me the right way to do it and The "embeddedUri#fontFamilyName" could you make me a example?

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,798 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.