开发者

How to load a grid from XAML codes and add it to a stackpanel dynamically/at runtime?

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"
        xmln开发者_如何学编程s: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!


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜