Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Loading resources from XAML, problem with fonts

Loading resources from XAML, problem with fonts

Scheduled Pinned Locked Moved WPF
htmlcsswpfcomhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jayme65
    wrote on last edited by
    #1

    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

    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)

    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: http://www.dafont.com/fr/digital-7.font)

    <Label FontFamily="pack://siteoforigin:,,,/Resources/#Digital-7" Content="Have a nice day!"/>
    

    ...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!

    P 1 Reply Last reply
    0
    • J Jayme65

      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

      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)

      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: http://www.dafont.com/fr/digital-7.font)

      <Label FontFamily="pack://siteoforigin:,,,/Resources/#Digital-7" Content="Have a nice day!"/>
      

      ...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!

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      You can always include the font as a content item. All you need to do is make sure that the font is available in the application directory. If you do this, you can then reference it like this:

      <Label FontFamily="#Digital-7" Content="Have a nice day!" />

      This space for rent

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups