Loading XAML at runtime
-
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 ClassThank you!
-
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 ClassThank you!
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