PerfectPhase said:

Coming soon in XAML-2009 non-default constructors....

 

<coll:List x:Key='list' x:TypeArguments='x:String' x:FactoryMethod='local:Factory.CreateStringList'>

    <x:Arguments>

        <x:String>Mickey,Donald</x:String>

    </x:Arguments>

</coll:List>

 

via: http://blogs.msdn.com/llobo/archive/2009/11/20/xaml-2009-features-factorymethod-arguments.aspx

 

You might want to have a look at the noode stream support in System.Xaml (see PDC2008 - TL36)  You can proberbly do what ever you like if you use XamlObjectReader and XamlXmlWriter rather than XamlServices.

@exoteric-

You can work with Non-Default Constructors

XamlServices.Save() in .Net 4 can write instances which need non-default constructors to be created. In order to tell the Save() routine (or really the XamlObjectReader under the covers) which constructor to use, you must have a TypeConverter or ValueSerializer that can return an InstanceDescriptor given the instance.

 

RoundTripping

Yes, XamlServices.Save() currently attempts to only ever write things that can be read. Would love to understand what properties you want to write, and why. Do you intend to try to read them later?

PerfectPhase mentions using XamlObjectReader and XamlXmlWriter and added the functionality you want.  XamlObjectReader has an Instance property, which should enable you to see the current object that the XOR is dealing with...perhaps you could inject additional XAML nodes via a XAML node loop.

 

Ways that WPF has dealt with default Constructors and immutability

In WPF, some types inherit from Freezable which enables a pattern of r/w properties until they Freeze() is called, then they throw if you try to set them.

 

Hope that helps. Look forward to more feedback/discussion.

 

Thanks,

Rob Relyea

XAML Team

http://robrelyea.com/blog