Welcome to MSDN Blogs Sign in | Join | Help

Using CreateFromXaml() in WPFe? XamlStringBuilder could save you time!

In WPFe JavaScript code, it's handy to be able to build up a xaml string dynamically, then call CreateFromXaml() to create the elements on the fly. What can be a pain is coding up your string buildup in JavaScript.

I wrote a quick tool (depends on 2.0 CLR) that allows you to type or paste xaml XML into a top pane, then generate the equivalent xaml string buildup code in JavaScript. You can then click a "Copy to Clipboard" button, return to your WPFe project, and paste in the string buildup code. (See attached file)

 Hope this is helpful!

Screenshot: 

Published Friday, April 06, 2007 8:43 AM by GavinGear

Attachment(s): XamlStringBuilder.exe

Comments

# Gavin Gear's XAML-> Javascript String Converter

Friday, April 06, 2007 11:59 AM by Mike Harsh's Blog

Gavin Gear of the Ink team has created a WinForms app that takes a XAML string and turns it into a javascript

# re: Using CreateFromXaml() in WPFe? XamlStringBuilder could save you time!

Friday, April 06, 2007 3:03 PM by tfries

At the risk of looking like I'm nitpicking a quick tool, there are a couple issues:

1. If any of your attribute values contain an apostrophe, even if the apostrophe is represented as an "apos" entity, the resulting Javascript string is invalid XML.

2. Concatenating strings in Javascript has the same overhead as it does in .NET -- every concatenate copies the entire string. The generated code would be faster and consume less memory if it pushed the strings onto a Javascript array, then used the join() method of the array to generate the final string.

# re: Using CreateFromXaml() in WPFe? XamlStringBuilder could save you time!

Friday, April 06, 2007 8:57 PM by InfinitiesLoop

Nice. How about support for going the other way around? That way you don't have to save the actual xaml if you want to update it, you can always get back to the xaml from the javascript.

# WPF/E Links...

Saturday, April 14, 2007 12:32 PM by MrDave's (David Yack) Blog!

For those of you that attended my talk in Salt Lake City - here's the links I referred to in my talk...

# re: Using CreateFromXaml() in WPFe? XamlStringBuilder could save you time!

Wednesday, April 18, 2007 4:46 PM by interactive

Gavin, you should change the JavaScript output to this:

var a = [];

a.push("<Canvas....>");

a.push("...");

a.push("</Canvas>");

var xaml = a.join("");

If used often this is a performance benefit while running JavaScript.

Michael

Anonymous comments are disabled
 
Page view tracker