Get XAML Source WPF Window

I would like to get the XAML source of a WPF window (MainWindow). Clicking on the button in this window will return the XAML window, and I will save it in another file.

Is this possible and how can it be achieved?

+3
source share
3 answers

You can use XamlWriter:

using (Stream stream = File.OpenWrite("D:\\Test.xaml"))
{
    XamlWriter.Save(this, stream);
}
+3
source

You can use XamlWriter for some basic Xaml serialization. In particular, look at this article for limitations .

+2
source

, , , XAML, ( ), API Reflector BAMLViewer.

BAMLViewer solves a different problem than XamlWriter: using Reflector / BAMLViewer will return the original source XAML with all the links, etc. intact, but will not include the current property values. Using XamlWriter will include current property values, but things such as resource references and markup extensions will be lost. In addition, some things will not be serialized using XamlWriter.

You must choose between them depending on the needs of your application.

0
source

Source: https://habr.com/ru/post/1735059/


All Articles