Shailesh Kumar
Shailesh Kumar

Reputation: 6967

how to read xaml from assembly

To navigate to a specific page in the assembly, the typical code looks like:

NavigationService.Navigate(new Uri("pagename.xaml", UriKind.Relative));

I was wondering if there is a way to read the contents of this XAML file or may be a way to decompile the embedded BAML file from the assembly directly.

Upvotes: 2

Views: 1222

Answers (1)

Ivan Zlatanov
Ivan Zlatanov

Reputation: 5226

To instantiate the control from your assembly you need to do the following:

    Uri uri = new Uri( "/YourApplication;component/YourWindow.xaml", 
                    UriKind.Relative );
    Window window = (Window)Application.LoadComponent(uri);

where Window is the top element of this file. If you want the actual XAML you can use XamlWriter to give that to you:

String xaml = XamlWriter.Save( window );

Upvotes: 4

Related Questions