Create Button from Xaml string
//File:Window.xaml.cs
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Markup;
using System.Xml;
using System.IO;
namespace WpfApplication1
{
public partial class Window1 : System.Windows.Window
{
public Window1()
{
InitializeComponent();
StringReader sr = new StringReader(@"");
XmlReader reader = XmlReader.Create(sr);
Button dynamicButton = (Button)XamlReader.Load(reader);
this.grid1.Children.Add(dynamicButton);
dynamicButton.Click += button1_Click;
}
private void button1_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Dynamic Button Loaded From XAML String");
}
}
}