Silverlight – Adding Xaml to custom controls at run time

System.IO.Stream s = this.GetType().Assembly.GetManifestResourceStream(“YourNamespace.YourControl.xaml”);
implementationRoot =
this.InitializeFromXaml(new System.IO.StreamReader(s).ReadToEnd());

Canvas rootCanvas = (Canvas)implementationRoot;
Rectangle r = (Rectangle)XamlReader.Load(“<Rectangle Width=’10’ Height=’10’ Fill=’#FF000000′ />”);
rootCanvas.Children.Add(r);

http://forums.silverlight.net/forums/t/5727.aspx

Leave a comment