I have been experimenting with WPF and rendering strict XAML markup in a web browser, also known as Loose XAML (explained here and here).

It strikes me as mostly useful for displaying static content. However, it also appears possible to bind to an XML data provider.

Loose XAML files are not compiled with an application, which creates the following limitations:

  • They do not allow external assemblies
  • No use of classes, code-behind (or any C#)
  • No two-way databinding

What additional limitations are there?

  • I have not found a way to databind to a database provider (SQL Server)
  • Is the .NET Framework required on the client machine in order to render the XAML in the browser?
  • Are Search Engines able to interrogate Loose XAML to appropriately rank the pages?

EDIT: I have attempted to bind the XML data provider to a web service (using this simple example) and have not been successful. These findings lead me to further research where I found that it this is not supported: "The XMLDataProvider is designed to be read-only (in other words, it doesn't provide the ability to commit changes), and it isn't able to deal with XML data that may come from other sources (such as a database record, a web service message, and so on)." -Matthew MacDonald, Pro WPF

+2  A: 

At least framework 3.0 is required to view loose XAML pages in IE. You can even check for it on your site by looking for ".NET CLR 3.0" in the user agent string.

A database connection, if it is even possible, would not be done directly in the loose XAML because of the need for procedural code to open the connection.

Joel B Fant
i am not sure why this is even an issue. loose xaml should be compared to HTML. you can't open a database connection from a client side javascript either. you'd have to do that work on the server and then send page already with the database information to the client. why wouldn't you do the same with loose xaml.. the server constructs the xaml with the data and sends it to the client
+1  A: 

AFAIK it's impossible to define a connection string in XAML. So you can't access your SQL db.

Note: It IS possible to databind to a webservice however using XmlDataProvider. So that could be a way you could send your data through...

Edit: btw, I found this list of features of the Sandboxed environment, which your app is running in when using XBAP and loose XAML. it's a bit dated, but probably most limitations still apply.

Ruben Steins

I've done a lot of work in hosting the Dynamic Language Runtime (DLR) and allowing scripts to be embedded in XAML. I'm at the point now that I feel like Loose XAML is not a second class citizen as I can handle events, write value converters, run Python/Ruby/JScript to do things like connect to SQL server.

See my blog to see if this direction suits you.

I dynamically load assemblies using an attached property - once loaded, you can reference the classes in the assembly in the usual manner.

So, too answer the question, there are MANY limitations of Loose XAML out of the box (like not being able to route an event to an event handler), but these can be overcome with a bit of work.

I've only used XAML/WPF for desktop apps. Hopefully someone else jumps in to answer you browser specific questions.

I have a library that I use in commercial work for DLR hosting and embedding DLR scripts in XAML that I've been meaning to turn into a supported product. If this would be of interest to you, be sure to let me know.

Daniel Paull