1

this code converts any controls or object to xml


if I saved this
screenshot


the saved xml would be looks like:

<Grid Name="g" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Image Source="pack://application:,,,/WpfApplication1;component/Images/Picture3.jpg" Stretch="Fill" Name="image1" Width="200" Height="150" Margin="96,36,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" />
<Button Name="button1" Width="75" Height="23" Margin="352,71,0,0" HorizontalAlignment="Left" VerticalAlignment="Top">Button</Button>
<TextBox Name="textBox1" Width="120" Height="23" Margin="62,198,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" xml:space="preserve" />
<Label Name="label1" Height="28" Margin="270,213,0,0" HorizontalAlignment="Left" VerticalAlignment="Top">Label</Label>
</Grid>


I used this code to save this:

 System.IO.StreamWriter s = new System.IO.StreamWriter(@"d:\grid.xml");
            s.WriteLine(System.Windows.Markup.XamlWriter.Save(g));
            s.Close();

g is the name of the grid which contains all controls

my question:
can I reverse this, read this xml file and represent it on a window

1

2 Answers 2

1

Just use the XAML Reader Class.

Sign up to request clarification or add additional context in comments.

1 Comment

@Amged: There's an example in the link I posted, just scroll down.
0
var somecontrol = XamlReader.Load(@"<ItemsPanelTemplate
                xmlns=""http://schemas.microsoft.com/client/2007"" 
                xmlns:toolkit=""http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"">
                <toolkit:WrapPanel /></ItemsPanelTemplate>");

1 Comment

error 'System.Xaml.XamlReader' does not contain a definition for 'Load'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.