How can I load XAML which is from the DataBase into the grid control in C#, How can I load that xaml into Grid Control ?
But how to assign that XAML to Grid Control?
Asim Sajjad
2010-04-14 08:52:46
Did you visit the link? Once you have executed XamlReader.Load() you have a control that you can add to your object tree (i.e. you can add it as a child control to another already existing control). Go to the link, there is a code example at the bottom.
slugster
2010-04-14 11:13:09
StringReader stringReader = new StringReader(savedButton);XmlReader xmlReader = XmlReader.Create(stringReader);Button readerLoadButton = (Button)XamlReader.Load(xmlReader);this the code which is there, I have visited it and I have visited it Again. my question is that I have Grid objGrid=new Grid();how can I load that XAML in the Grid. I don't know that will be there in the XAML , it could be viewBox, button any control.
Asim Sajjad
2010-04-15 05:55:19
Use the *Children* property. Like this: Grid g = new Grid(); g.Children.Add(new Button()); Whatever you add has to derive from *UIElement*, which most controls do.
slugster
2010-04-15 06:43:44
it mean there is no direct way to assign the XamlReader.Load() to the grid control , like the button contro which has the property Content , to which the XamlReader.Load() can be assign.
Asim Sajjad
2010-04-15 07:07:06
I'm failing to see your problem here. The Grid and Button are different types of control, so they do things slightly differently - and i've shown you how to load some arbitrary xaml as a control in to the Grid. You can do it in one statement if you wish: *g.Children.Add((Button) XamlReader.Load("my XAML"));*
slugster
2010-04-15 07:27:04
A:
you can use XamlReader.Load method to load xaml dynamically. You cannot use any code behind if you are loading dynamic xaml.
Just create a stream and pass that stream to the load method of the xamlreader.
Kishore Kumar
2010-04-13 10:41:05