Friday, April 20, 2007

Creating a control from xaml string at runtime

string s = "< Button xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' >";
s += "Hai";
s += " < /Button > ";

Stream strm = new MemoryStream(ASCIIEncoding.Default.GetBytes(s));
Button b = (Button)System.Windows.Markup.XamlReader.Load(strm);
stackPanel.Children.Add(B);

2 comments: