You could modify WpfApp4
to your project name (namespace), my example here should be changed to FontFamilyDemo
.
You should also modify the path of Fonts.xaml according to the path where your fonts are located.
Project and resource path structure:
2.Right click on the .ttf file, select Properties and set Build Action to Resource:
Fonts.xaml:
<FontFamily x:Key="BuxtonSketch">pack://application:,,,/FontFamilyDemo;component/Fonts/#SourceSansPro-Bold</FontFamily>
<FontFamily x:Key="Murder">pack://application:,,,/FontFamilyDemo;component/Fonts/#Source Sans Pro Black</FontFamily>
<FontFamily x:Key="Pacifico">pack://application:,,,/FontFamilyDemo;component/Fonts/#Pacifico</FontFamily>
MainWindow.xaml:
<StackPanel>
<TextBlock Name="tb" VerticalAlignment="Bottom"
HorizontalAlignment="Right" Text="0.0.0" Background="AliceBlue"
FontSize="20"
Margin="0, 0, 5, 0"/>
<TextBlock Name="light" VerticalAlignment="Bottom"
HorizontalAlignment="Right" Text="0.0.0" Background="AliceBlue"
FontFamily="{StaticResource Pacifico}" FontSize="20"
Margin="0, 0, 5, 0"/>
<Button Name="btn" Content="Check" Height="60"
FontSize="28" Foreground="#DDFFFFFF" Margin="0, 0, 0, 15" VerticalAlignment="Bottom"
HorizontalAlignment="Center" MinWidth="150" Background="#FFFF9700" Padding="10,1,10,1"/>
<Button Name="PlayButton" Content="Check" Height="60" FontFamily="{StaticResource Murder}"
FontSize="28" Foreground="#DDFFFFFF" Margin="0, 0, 0, 15" VerticalAlignment="Bottom"
HorizontalAlignment="Center" MinWidth="150" Background="#FFFF9700" Padding="10,1,10,1"/>
</StackPanel>
The result:
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.