WPF versus WPF/E

I sat down to look at WPF/E this evening. WPF/E is Microsoft's cross-platform XAML engine that runs in a web browser. The technology is currently in a community preview stage.

I thought a good first step would be to port my "Game of Life" WPF application to WPF/E and see the game run in a browser. A quick look at the documentation revealed that WPF/E doesn't support data binding, resources, or layout controls (like the Grid). 

A good contrast will be to compare the following snippet of WPF code to my hacked up WPF/E equivalent. This C# code dynamically creates a "life" indicator in each cell of a grid control.

Ellipse ellipse = new Ellipse();
Grid.SetColumn(ellipse, column);
Grid.SetRow(ellipse, row);
ellipse.DataContext = _cells[row, column];
mainGrid.Children.Add(ellipse);
ellipse.Style = Resources[
"lifeStyle"] as Style;

With no data binding, no resources, and no Grid control, the JavaScript code for WPF/E has to take an alternate route.

var xaml = '<Ellipse Height="7" Width="7" />';
var ellipse = this.agControl.createFromXaml(xaml);
ellipse.Fill =
this.CreateBrush();
ellipse.Opacity =
this.cells.isCellAlive(i,j) ? 1 : 0;

gameBoard.children.add(ellipse);

ellipse[
"Canvas.Top"] = (this.agControl.height / this.size) * i;
ellipse[
"Canvas.Left"] = (this.agControl.width / this.size) * j;

WPF/E has some clever solutions to tough problems. There is no Ellipse constructor function as you might expect. That approach would require a massive JavaScript file with functions defined for all the WPF/E objects. Instead, we create objects graphs using XAML fragments. The code merely needs to pass these fragments to the WPF/E ActiveX control's createFromXaml method and receive an object in return. Also, notice the syntax for attached properties in WPF/E (ellipse["Canvas.Left"]).

If I had $100 to spend on WPF/E features, I'd spend the whole lot on adding data binding and layout controls. Overall, WPF/E is a bit different from what I expected before I started this evening. At this stage, the technology is good for performing animations, and playing media. No small feat, really, but anything the team can add that will facilitate day-to-day business requirements (build a dashboard of key performance indicators, fill out an insurance claim form) would make the technology terrific.

posted on Thursday, December 28, 2006 12:17 AM by scott

Comments

Thursday, December 28, 2006 2:05 AM by Rick Strahl

# re: WPF versus WPF/E

Yeah that's what I thought as well. It seems even the full WPF isn't really geared towards business scenarios with providing only the most rudimentary of controls. Everything fancy (complex lists or trees, grids etc. or even formatted input controls etc.) are strangely lacking from WPF in general. Line of business applications is apparently not the target...
Thursday, December 28, 2006 3:53 AM by Strange Pants

# re: WPF versus WPF/E

Until WFP and WFP-E are identical (i.e. code once, run anywhere) why would you even bother? If you are going to have to write the application twice, you might as well rewrite for the browser itself (ASP.NET?).

I realise WFP-E holds a lot of promise for changing the UI paradigm, but ... this really does look like yet another half-baked product from Microsoft in a year full of half-baked products.
Thursday, December 28, 2006 8:11 AM by admin

# re: WPF versus WPF/E

@Rick: Yes, the controls are rather primitive. I can only imagine WPF growing to include everything needeed to support business apps, but I wonder what WPF/E has in store.

@Strange Pants: My guess will be that code once run everywhere will never work, but its hard to say what things will look like 5 years for now.
Thursday, December 28, 2006 1:46 PM by scottgu

# re: WPF versus WPF/E

WPF/E with this first CTP has the same graphics support and parsing as WPF. What it doesn't have yet is control support (beyond the core visual elements) as well as layout manager support (layout management is part of the control model).

This is coming though...
Friday, December 29, 2006 9:30 AM by James Hancock

# re: WPF versus WPF/E

Basically what you're saying is that WPF/E is just flash by any other name at this point and there is absolutely no reason to use it when 99% of the graphic world knows flash and doesn't know WPF/E.

Until there is databinding native that can be created within the ActiveX (I don't know why I would care about javascript but...) this is essentially useless and has the exact same problems that flash does right now without all of the benefits of 99% computers on every platform having flash on it....
Friday, December 29, 2006 2:20 PM by Mike Harsh

# re: WPF versus WPF/E

Did you finish your WPF/E game of life? I didn't see a link. Also, as a better workaround to your ellipse constructor problem, see Jesse's response in this forum post:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=986258&SiteID=1

This will let you write code like:

var ellipse = createElement("Ellipse");
Friday, December 29, 2006 5:52 PM by scott

# re: WPF versus WPF/E

Mike: Thanks for the tip. I'll post the code this weekend.
Friday, January 05, 2007 11:32 AM by Mike Harsh's Blog

# Game of Life in WPF/E

K. Scott Allen rewrote his WPF version of Conway's Game of Life . He's got a commentary on the porting
Wednesday, May 30, 2007 6:08 AM by Mike Harsh's Blog

# More Silverlight Physics - K. Scott Allen's Swinging Rope

Last year (well, really early this year), Scott created a version of Conway's game of life in Silverlight
Wednesday, May 30, 2007 7:58 AM by Blogs

# More Silverlight Physics - K. Scott Allen's Swinging Rope

Last year (well, really early this year), Scott created a version of Conway&amp;#39;s game of life in Silverlight
Wednesday, May 30, 2007 8:20 AM by Blogs

# More Silverlight Physics - K. Scott Allen's Swinging Rope

Last year (well, really early this year), Scott created a version of Conway&amp;#39;s game of life in Silverlight
Tuesday, February 19, 2008 11:54 PM by Mirrored Blogs

# More Silverlight Physics - K. Scott Allen's Swinging Rope

Last year (well, really early this year), Scott created a version of Conway&amp;#39;s game of life in Silverlight