views:

97

answers:

1

It would be nice to have a tool in which you could copy and paste chunks of XAML such as this:

<StackPanel Margin="10">
    <TextBlock Text="Title"/>
</StackPanel>

And the tool would output the equivalent code behind such as this:

StackPanel sp = new StackPanel();
sp.Margin = new Thickness(10);

TextBlock tb = new TextBlock();
tb.Text = "Title";

sp.Children.Add(tb);

Does anyone know of a tool that does this?

+2  A: 

Rob Relyea has a tool called XamlT that converts Xaml to C# , www.xamlt.com

Running the simple example through it produced:

StackPanel StackPanel1 = new StackPanel();
StackPanel1.Margin = ((Thickness)new ThicknessConverter().ConvertFromString("10"));
Window1.Content = StackPanel1;

TextBlock TextBlock1 = new TextBlock();
TextBlock1.Text = "Title";
StackPanel1.Children.Add(TextBlock1);

the window.content line is because it does the entire window in code so was adding it as content.

Andrew