Reputation: 1654
I've decided to offload some of my UI generation to my back-end, and stream it to the client. This will allow me to make some UI changes without redeployment of the client.
Should be straightforward. On the server end:
string controlToStream = XamlWriter.Save(rootControl);
and on the client end:
var stringReader = new StringReader(value);
var xmlTextReader = new XmlTextReader(stringReader);
var control = XamlReader.Load(xmlTextReader);
But how do I get access to WPF on the server without introducing a full-blown WPF app in the chain? The server code is typical RPC type chunk of code, that gets executed each time a request comes in. Is there a way to get light-weight access to XAML/control creation in a console app?
thanks!
Solution Update for future reference:
Add references to WPF dlls (PresentationCore, Windowsbase, PresentationFramework, System.Xaml in my case) in console app
Make sure to only make calls to them from an STA thread. StaTaskScheduler from ParallelExtensionsExtras comes in handy: http://blogs.msdn.com/b/pfxteam/archive/2010/04/07/9990421.aspx
Upvotes: 0
Views: 761
Reputation: 244757
I'm not sure what exactly would you consider “light-weight”, but you can access all the WPF libraries from a console application.
If you don't want to use them for some reason, you could treat XAML as a normal XML, and use only a XML library to generate it. Although that's most likely going to be more work.
Upvotes: 1