0

In Silverlight 4, I would like to be able to pick from a dynamic list of UserControls and then display the full control after selection.

Meanwhile, in the list of UserControl options, I would like to display something more interesting than just a label or a scaled-down version of the UserControl's graphics. I would like to display a custom "thumbnail" that is defined in the control and exposed via a property that returns a UIElement (or straight XAML string).

So far I have attempted to draw the thumbnail within the XAML of the UserControl and expose that via a property as a UIElement. It has not worked for me (I get some sort of Silverlight rendering error). Is there a way to instead return the XAML of a child control as a string?

I imagine some solution like

XamlWriter.Write(UIElement);

It is key for me to be able to programmatically write the XAML of a control so that it can be designed in Blend.

YeahStu
  • 4,032
  • 5
  • 48
  • 69
  • I think you should use XamlReader.Parse and the ContentControl class. But maybe you mean something different, so I don't know what exactly you want. – vortexwolf Dec 12 '11 at 19:43
  • Yes, I am using that on the page that is loading the "dynamic list of UserControls" but that is not the problem. I need a way to generate the string (of XAML) from a compiled UserControl. – YeahStu Dec 12 '11 at 19:53

1 Answers1

0

It turns out this question is similar to the one asked here.

I have since found out that WPF includes a XamlWriter class with a Save method that does exactly what I want. Unfortunately, it is not included in Silverlight.

I ended up using the XamlWriter class that was created in the Silverlight Contrib project. It allows me to easily generate a string of XAML by referencing any UIElement.

Community
  • 1
  • 1
YeahStu
  • 4,032
  • 5
  • 48
  • 69