Navigation


Markus on Development and Publishing

This is Markus Egger's professional blog, which covers topics such as development, publishing, and business in general. As the publisher of CoDe and CoDe Focus magazines, and as the President and Chief Software Architect of EPS Software Corp., Markus shares his insights and opinions on this blog.

Content Area Footer

Friday, June 27, 2008
Persisting WPF Objects as XAML or XPS

Here's another thing people ask me about frequently: How can any in-memory WPF object be persisted as XAML? Here's how:

string xaml = System.Windows.Markup.XamlWriter.Save(some object);

This gives you the XAML that can then be persisted in a file or wherever, and it can be loaded dynamically or you could even use it as a new file in a project that gets compiled in. (Note that the created XAML can be pretty nasty compared to XAML crafted by hand or an editor).

Note: The System.Windows.Markup namespace also features a XamlReader object, which can be used to dynamically load XAML during runtime.

A similar scenario calls for converting to XPS. (XPS is basically the WPF version of PDFs). XPS is also XAML, but it is a little different in that XPS is a print-like presentation of what something looks like. XPS may use graphical elements (shapes) to represent something on screen, which is somewhat different from he above example that preserves the XAML objects as they were. (Conversion to XAML always saves a button as a <Button>, while XPS does whatever it wants to create something that looks the same, but it isn't an interactive button).

XML documents can be really great if you want to preserve the look of something exactly as is. This is generally used to save FlowDocuments as XPS. Check out this blog post for some details on that.



Posted @ 2:45 PM by Egger, Markus (markus@code-magazine.com)


 

 

 

 

 

 

 



My Twitter Status


    follow me on Twitter  


    Geo Caching
    Profile for MarkusEgger

    Syndication ng> RSS 2.0 RSS 2.0

    All My Blogs:
    My personal blogs:
    Dev and Publishing Dev and Publishing
    Travel and Internat. Living Travel and Internat. Living
    Other blogs I contribute to:
    Milos Blog (US) Milos Blog (US)
    VFPConv. Dev Blog (US) VFPConv. Dev Blog (US)
    VFPConv. Dev Blog (DE) VFPConv. Dev Blog (DE)

     

    Blog Archives
    All Blog Posts

    2012
        September (1)
        April (1)
        March (1)
    2011
        October (1)
        June (3)
        May (1)
        March (2)
        February (2)
        January (2)
    2010
        December (3)
        November (2)
        October (2)
        September (1)
        August (2)
        July (1)
        June (1)
        April (3)
        March (1)
        February (5)
        January (1)
    2009
        October (4)
        September (2)
        August (1)
        July (1)
        May (4)
        April (6)
        February (1)
        January (1)
    2008
        December (3)
        November (11)
        October (8)
        September (1)
        July (1)
        June (3)
        May (3)
        April (6)
        March (6)
        February (4)
    2007
        December (1)
        November (1)
        October (5)
        September (1)
        August (1)
        July (6)
        June (3)
        May (3)
        April (1)
        March (2)
        January (2)
    2006
        December (3)
        November (4)
        October (1)
        September (2)
        August (2)
        July (4)
        June (1)
        May (2)
        April (10)
        March (2)
        February (3)
        January (1)
    2005
        December (6)
        November (7)
        October (6)
        September (8)
        August (10)
        July (6)
        June (9)

     

     

     

    This Blog is powered by MilosTM Collaboration Components.