Tokk
Tokk

Reputation: 4502

Retrieve XAML from programmatically created UserControl at runtime

I'm creating a generator for UserControls in C#. It looks nearly like this:

UserControl control = new UserControl();
Grid contentGrid = new Grid();
control.Content = contentGrid;
//create Buttons, Labels, Bindings etc.
return control;

now my Question is whether I can get the XAML of the created UserControl at runtime, and if it is possible, how I can do that.

For instance from the Code above I want to retrieve Something like:

<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid>
       ....
    </Grid>
</UserControl>

Upvotes: 2

Views: 239

Answers (1)

svick
svick

Reputation: 244797

You can use XamlWriter.Save() for that, but it's limited.

Upvotes: 2

Related Questions