Results 1 to 1 of 1

Thread: Loading resources from XAML, problem with fonts!

  1. #1
    Jayme65 is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2011
    Posts
    35
    Reputation
    73

    Loading resources from XAML, problem with fonts!

    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
    Code:
    <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)
    Code:
    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)


    Code:
    <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 by Jayme65; 04-05-2016 at 4:14 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •