Viewing Albums with WPF/E and ASP.NET AJAX

Hopefully this is OK to post here. If not feel free to delete it.

I've been working on a WPF/E and ASP.NET AJAX demo over the holidays so I could learn WPF/E stuff better (the source of all my questions lately). The app turned out pretty good although there's still more I'd like to add. I'd love to hear better ways I should be doing things, etc. if anyone has time to play with it at all. The application ties into Amazon.com's Web Services to look-up albums and display them in a 3D type style.

Anyone interested can download the code and view a quick video I made about it here. Feedback and references to more appropriate ways to do things (especially in cases where there was an easier way than I did it) are certainly welcome.

http://weblogs.asp.net/dwahlin/archive/2007/01/05/viewing-albums-with-wpf-e-and-asp-net-ajax.aspx

[1299 byte] By [DanWahlin] at [2008-1-22]
# 1

I was testing out different artist searches and found an unhandled exception that gets raised when a bad image is passed into CreateFromXaml() and the resulting object is added to the child collection. The image exists although nothing shows so I’m guessing the .jpg file is corrupt or something (http://images.amazon.com/images/P/B000000WZI.01.MZZZZZZZ.jpg). If you try the app above and do a search for Erasure you’ll see the issue in album 9 if you step through the UpdateXaml() function (my fallback onError handler is called now to fix the problem).

function UpdateXaml(fragments) {

var tb = $get("txtXaml");

tb.value = "";

for (var i=0;i<fragments.length;i++) {

if (_Debug) tb.value += fragmentsIdea;

try {

if (_InError) { //Caused by unhandled exception due to album image being bad

_AlbumsCanvas.Children.RemoveAt(i-1);

_InError = false;

}

var newAlbum = _WpfeControl.CreateFromXaml(fragmentsIdea);

_AlbumsCanvas.Children.Add(newAlbum);

}

catch (e) {}

}

if (_InError) { //Bad image likely so remove last child that would've caused it

if (fragments.length > 0) _AlbumsCanvas.Children.RemoveAt(fragments.length-1);

_InError = false;

}

_ArtistText.Text = (_Albums[0].Artist.length > 40)?_Albums[0].Artist.substring(0,40) + "...":_Albums[0].Artist;

_WpfeControl.findName("ArtistTextLine").Opacity = ".5";

}

function onError(line, col, hr, string) {

_InError = true;

}

Anyway, I handled the issue by setting an _InError variable in the onError() method that gets called (notice that the fallback error function is called even though I wrap the error lines in a try…catch block above). When I detect an error occurred with an album I remove that child from the collection and then things seem to work. I think the Add() method needs to have a way to handle this and potentially just not add the “bad” child and then return null rather than throwing the unhandled exception. Probably what is already planned. :-)

DanWahlin at 2007-9-4 > top of Msdn Tech,Silverlight (formerly WPF/E),Silverlight (formerly WPF/E) General Discussion...
# 2
Update on the above post. It looks like the bad image related exception is unhandled in IE7 (fallback error handler is hit) but is handled with the try...catch in FireFox 2. I updated the try...catch block to add _InError = true; in the catch and things work fine in FireFox now.
DanWahlin at 2007-9-4 > top of Msdn Tech,Silverlight (formerly WPF/E),Silverlight (formerly WPF/E) General Discussion...
# 3

The ability to properly set the Canvas.Top property through JavaScript is working in the February release so I decided to enhance my Album Viewer application and allow users to move the albums in a carousel type movement.

http://weblogs.asp.net/dwahlin/archive/2007/02/23/wpf-e-and-asp-net-ajax-albumviewer-application-now-live.aspx

DanWahlin at 2007-9-4 > top of Msdn Tech,Silverlight (formerly WPF/E),Silverlight (formerly WPF/E) General Discussion...