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:

  1. thanks i'm looking for this example for like an houre thank you very much

    ReplyDelete
  2. Happy to hear that my post helped you

    ReplyDelete