I would like to get the XAML source of a WPF Window (MainWindow). Clicking on a button on that window would return the XAML of the window and I would save it in another file.
Is this possible and how can it be achieved?
You can use the XamlWriter:
using (Stream stream = File.OpenWrite("D:\\Test.xaml"))
{
XamlWriter.Save(this, stream);
}