Posted By: Ian2 | Oct 26th @ 7:17 AM
page 1 of 1
Comments: 6 | Views: 115
Ian2
Ian2
Proud to geek ..

Does anyone know of a utility to convert XAML into CSharp?  (assuming this is possible?)

Dr Herbie
Dr Herbie
Horses for courses

Hmm.  That's a good question: presumably somewhere in the .NET framework there is code to do this?  I mean, through the .NET libraries you have access to the C# compiler and even to the dialog designer so I would have though the XAML loading classes would be there somewhere ....

 

Herbie

 

It has to exist since this is what Visual Studio does when it builds your WPF app.

stevo_
stevo_
Human after all

Not exactly, the xaml generates an object tree which can be persisted into a binary format, it can also be iterated to get objects that are keyed so they can be generated.

 

In terms of actually changing xaml into c#, you would really be better looking into generating C# from object graphs, this way you don't have to replicate xaml behavior, and can do: XAML -> Object graph -> C#.

 

You'll be able to get keys from the objects by using whatever class it is that xaml uses to determine keyd objects, which has overrides to detect class specified keys.

 

You'll have much more success using .NET 4, otherwise you'll need to depend on wpf assemblies and theres a certain amount of hard links in pre .net 4 xaml to wpf behavior.

 

If you don't want to use object graphs then you'll need to replicate some work that xaml does where it reflects the target member to determine how it handles value conversions etc.

Dr Herbie
Dr Herbie
Horses for courses

In a previous job, I worked on a system where the UI was editable at runtime (originally in MFC and later rewritten in C# for desktop and asp.net). The layout was stored in a database.  I have often thought about trying to do something similar in WPF (or at least with alimited subset of WPF). XAML would be a useful import/export format.

 

Herbie

stevo_
stevo_
Human after all

I think once you see the code equiv of the xaml markup you'll pick the xaml over it Tongue Out, theres going to be a lot of weird looking calls to attached property setters, lots more instances than you see in the markup, such as markup extensions, and value expansions.

 

Personally I don't quite see what you'd use it for but.

 

Also: http://mono-project.com/Summer2005#XAML_compiler

page 1 of 1
Comments: 6 | Views: 115
Microsoft Communities