views:

1225

answers:

3

I am trying to send my dynamically created silverlight 2 page/image to a an ASP.net web service to render it as an bitmap image.

I can see many examples how to get the XAML using javascript (see here) in version 1 of silverlight but I have a few differences.

a) I am using silverlight 2 RC1
b) I have dynamically add controls to the page in c#
c) I would prefer to use c# to get the new XAML to keep all the coed in one place.

does anyone know how to extract the XAML from a control or the page in c#?

Thank you


Update: This is now possible under silverlight 3 using a writable bitmap to save the XAML as a JPEG see my blog post here: http://blog.blueboxes.co.uk/2009/07/21/rendering-xaml-to-a-jpeg-using-silverlight-3/

A: 

Hi John, unfortunately there is not a method for a .ToXaml() on an element tree unfortunately. You can use VisualTreeHelper to build such a method and recurse through a particular element I suppose.

Tim Heuer
This is now possible under silverlight 3 see post for update
John
A: 

Check out this link to see if it will help you at all. http://blogs.vertigo.com/personal/ralph/Blog/archive/2008/11/21/snapshot-of-xaml-control-save-to-image.aspx

Tom
A: 

SilverlightContrib has a XamlWriter class that can extract the XAML from a live control.

It's free.

The link is: http://silverlightcontrib.org

The code would be something like:


// using SilverlightContrib.Xaml;

            var cb = new GroupBox();
            StringBuilder sb = new StringBuilder();
            XamlWriterSettings settings = new XamlWriterSettings();

            using (XamlWriter writer = XamlWriter.CreateWriter(sb, false, settings))
            {
                writer.WriteElement(cb);
            }

            string result = sb.ToString();

Klinger