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 XAML at runtime

Loading XAML at runtime

Scheduled Pinned Locked Moved WPF
csharphtmlcsswpf
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

    Hi, I'm working on loading xaml code at runtime. Until now, I can do it with XAML files which are set as "Resource"...but I would like to load it from a user's folder (let's say the "Desktop Folder" for example) How should I please proceed? The XAML example file, loaded as resource file in my project (but I would like to use it "independently")

    The Application XAML code

    The Application VB.Net code

    Class MainWindow
    Private Sub MainWindow_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
    Dim GridUri As New Uri("Resources\theme.xaml", UriKind.Relative)
    Dim sri As Windows.Resources.StreamResourceInfo = Application.GetResourceStream(GridUri)
    Dim xrdr As New System.Windows.Markup.XamlReader()
    Dim grd As Grid = CType(xrdr.LoadAsync(sri.Stream), Grid)
    Me.Content = grd
    End Sub
    End Class

    Thank you!

    M 1 Reply Last reply
    0
    • J Jayme65

      Hi, I'm working on loading xaml code at runtime. Until now, I can do it with XAML files which are set as "Resource"...but I would like to load it from a user's folder (let's say the "Desktop Folder" for example) How should I please proceed? The XAML example file, loaded as resource file in my project (but I would like to use it "independently")

      The Application XAML code

      The Application VB.Net code

      Class MainWindow
      Private Sub MainWindow_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
      Dim GridUri As New Uri("Resources\theme.xaml", UriKind.Relative)
      Dim sri As Windows.Resources.StreamResourceInfo = Application.GetResourceStream(GridUri)
      Dim xrdr As New System.Windows.Markup.XamlReader()
      Dim grd As Grid = CType(xrdr.LoadAsync(sri.Stream), Grid)
      Me.Content = grd
      End Sub
      End Class

      Thank you!

      M Offline
      M Offline
      marimuthu26
      wrote on last edited by
      #2

      if your application is WPF application you can load a physical file

      Imports System.Windows.Markup

      Class MainWindow

      Private Sub Window\_Loaded(sender As System.Object, e As System.Windows.RoutedEventArgs)
          Dim objXaml = XamlReader.Load(IO.File.Open(Environment.CurrentDirectory & "Resource\\theme.xaml", IO.FileMode.Open))
      End Sub
      

      End Class

      if it was a silverlight application you cant do that :(

      ... Marimuthu

      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