Page 1 of 1

FontFamily in xaml

Posted: Mon Apr 03, 2017 4:56 am
by kmatt
I can't get the <FontFamily> to work in xaml even though it was supposedly released in beta 7. There is no parameterless constructor for it, which automatically means it can't work in xaml. How then do you use it as a StaticResource?

Re: FontFamily in xaml

Posted: Mon Apr 03, 2017 5:23 am
by JS-Support @Userware
Hi,

I got the following XAML code to work, can you please tell me if this is the same approach that you are using? (please ignore possible design-time XAML editor errors)

Code: Select all

<Border>
    <Border.Resources>
        <FontFamily x:Key="TestFont">Wingdings</FontFamily>
    </Border.Resources>
    <TextBlock Text="This is a test" FontFamily="{StaticResource TestFont}"/>
</Border>


Thanks.
Regards,
JS-Support

Re: FontFamily in xaml

Posted: Thu Apr 06, 2017 5:09 am
by kmatt
I thought I would get a notification when a reply was posted, but I did not.

No, not exactly. I've tried several ways:

<Page.Resources>
<ResourceDictionary>
<FontFamily x:Key="EatonLightFont">Arial</FontFamily>
</ResourceDictionary>
</Page.Resources>

<Page.Resources>
<FontFamily x:Key="EatonLightFont">Arial</FontFamily>
</Page.Resources>

Which would then be called out like so:
FontFamily="{StaticResource EatonLightFont}"
inside an element like a Listbox or other control, in the Page, ChildWindow and UserControl elements, and:

<ChildWindow.FontFamily>
<StaticResource ResourceKey="EatonLightFont"/>
</ChildWindow.FontFamily>

In the same places (ChildWindow, UserControl and Page).

Re: FontFamily in xaml

Posted: Thu Apr 06, 2017 8:50 am
by JS-Support @Userware
Hi,

Thanks a lot for your reply.

For a quick resolution, can you please reproduce the issue in a new empty project and attach it to this thread? This way we can reproduce it as well and fix it very quickly.

Thanks again.
Regards,
JS-Support

Re: FontFamily in xaml

Posted: Fri Apr 07, 2017 11:09 am
by kmatt
I'm sorry, but I can't completely reproduce it in a small project with only a button. It was there in the new small project until I got rid of the last "other" compiler error (I had no method yet for the button click), but when I added the OnClick method the FontFamily compiler error went away too. I can't eliminate all of my project down to a single button, so that doesn't help much. By the way, the error shows up in the xaml file (as squiggly lines under the FontFamily) and in the compiler. In my real project I don't get any other compiler errors or squiggly lines in the xaml, just the FontFamily one.

Re: FontFamily in xaml

Posted: Fri Apr 07, 2017 12:04 pm
by kmatt
Apparently ANY StaticResource Xaml properties are my issue. Once I removed all the FontFamily ones, my ButtonStyle ones started showing up as errors.

Re: FontFamily in xaml

Posted: Fri Apr 07, 2017 3:31 pm
by JS-Support @Userware
Thanks for the reply. Does the FontFamily error appear also if you close the XAML editor and recompile the project?