Question Loading resources from XAML, problem with fonts!

Jayme65

Active member
Joined
Apr 5, 2011
Messages
35
Programming Experience
Beginner
I am (I have to) using an XAML file as a resource from my main window.
In this simplified example, the XAML file looks like this
VB.NET:
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="themeGrid">
    <Image Height="Auto" HorizontalAlignment="Left" Margin="0" Stretch="Fill" VerticalAlignment="Top" Width="Auto">
        <Image.Source>
            <BitmapImage UriSource="pack://siteoforigin:,,,/Resources/image1.jpg" CacheOption="OnLoad" />
        </Image.Source>
    </Image>
</Grid>

The file is loaded that way (the XAML file, as well as a 'image1.jpg' file, are in a 'Resources' folder along with the exe file)
VB.NET:
Imports System.IO
Class MainWindow
    Private Sub MainWindow_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        loadInterface()
    End Sub
    Sub loadInterface()
        ' Load xaml file as content of the window
        Dim GridUri As String = System.AppDomain.CurrentDomain.BaseDirectory & "Resources\theme.xaml"
        Dim fs As FileStream = New FileStream(GridUri, FileMode.Open, FileAccess.Read)
        Dim sri = TryCast(System.Windows.Markup.XamlReader.Load(fs), Grid)
        Me.Content = sri
        fs.Close()
    End Sub
End Class

..and that works nicely

Now I would like to use a label whit a font file taken in the same 'Resources' folder (the font used in this example: Digital 7 | dafont.com)


VB.NET:
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="themeGrid">
    <Image Height="Auto" HorizontalAlignment="Left" Margin="0" Stretch="Fill" VerticalAlignment="Top" Width="Auto">
        <Image.Source>
            <BitmapImage UriSource="pack://siteoforigin:,,,/Resources/image1.jpg" CacheOption="OnLoad" />
        </Image.Source>
    </Image>
    <Label FontFamily="pack://siteoforigin:,,,/Resources/#Digital-7" Content="Have a nice day!"/>
</Grid>

...but then the label text isn't displayed with the proper FontFamily!

What should I please do for the text of the label to be displayed using the font in the resources folder?
Thanks very much!!

PS: the font file CAN'T be in resource of the application. Think of this XAML as a theme, any font could be inside and the application couldn't have all those possible fonts in resources!
 
Last edited:
Back
Top