views:

15

answers:

1

I generate the XAML codes which actually describe a valid grid control - called the GridXAML. I want to create a grid object and add it to a stackpanel on my form.

How can I 1) create an object from its XAML string value, and 2) add it dynamically to a panel? Please help!

Giving a specific sample context as below. The generated grid's xaml:

<Grid>
  <Textblock Text="abb" />
</Grid>

The current main form of my WPF application.

<Window x:Class="MyApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="333" Width="111">
    <StackPanel x:Name="MyStackPanel" Orientation="Vertical">
        <!--I want the grid appear here at runtime-->
    </StackPanel>
</Window>

All helps are very much appreciated!

+1  A: 

Use the XamlReader's XamlReader.Load() or XamlReader.Parse()

rudigrobler
@rudigrobler: Can you make it more specific?
Nam Gi VU