K
K
kokapuk2022-02-05 15:36:23
WPF
kokapuk, 2022-02-05 15:36:23

How to add web fonts to my application?

Hello, this is not the first time I am developing my program in WPF, but I have not encountered this problem before. The bottom line is that in order to use fonts from the Internet, it was enough to throw it into the project through the browser. And the font does appear in the selection list, but nothing changes when you select it. With what it can be connected?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Makzzzimus, 2022-02-06
@kokapuk

Look, when you add fonts, be sure to set the Resource property through Visual Studio.
Then add the following lines to your app.xaml file.

<ResourceDictionary>
            <FontFamily x:Key="Dongle-Regular">./Data/Fonts/Dongle-Regular.ttf#Dongle</FontFamily>
            <FontFamily x:Key="Dongle-Light">./Data/Fonts/Dongle-Light.ttf#Dongle</FontFamily>
            <FontFamily x:Key="Dongle-Bold">./Data/Fonts/Dongle-Bold.ttf#Dongle</FontFamily>
        </ResourceDictionary>

The only thing is that you change the name and path for the fonts.
And now you can choose fonts for your text. Add the following line in the Xaml file for text:
FontFamily="{StaticResource Dongle-Regular}"

A
Alexander, 2022-02-05
@Adler_lug

Is using fonts in WPF any different from using them in WinForm?
If not, then Google is full of information, for example , and there is even a video .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question