Benutzer:MovGP0/WPF/Fonts

aus Wikipedia, der freien Enzyklopädie
   MovGP0        Über mich        Hilfen        Artikel        Weblinks        Literatur        Zitate        Notizen        Programmierung        MSCert        Physik      


WPF Fonts

Eigene Fonts in Projekt einbinden[1]

MyProject.csproj
<ItemGroup>
    <Resource Include="Fonts\NotoSans-Bold.ttf" />
    <Resource Include="Fonts\NotoSans-BoldItalic.ttf" />
    <Resource Include="Fonts\NotoSans-Italic.ttf" />
    <Resource Include="Fonts\NotoSans-Regular.ttf" />
    <Resource Include="Fonts\NotoSansSymbols-Regular.ttf" />
</ItemGroup>
App.xaml
<Applicaton ...>
    <Application.Resources>
        <FontFamily x:Key="NotoSans">pack://application:,,,/Fonts/#NotoSans</FontFamily>
        <FontFamily x:Key="NotoSansSymbols">pack://application:,,,/Fonts/#NotoSansSymbols</FontFamily>
    </Application.Resources>
</Application>
Window.xaml
<TextBlock x:Name="myTextBlock" Text="foobar" FontFamily="{StaticResource NotoSans}" 
           FontSize="10.0" FontStyle="Normal" FontWeight="Regular" />
Window.xaml.cs
    var uri = new Uri("pack://application:,,,/");
    myTextBlock.FontFamily = new FontFamily(uri, "./Fonts/#NotoSans");

Links

Referenzen

  1. Packaging Fonts with Applications. In: MSDN. Microsoft, abgerufen am 7. Oktober 2016 (englisch).