Page view counter

Silverlight Debugging Challenge

In about a week, I'll be posting a video on creating a form that responds to keyboard shortcuts (as an intro to a video on user controls).

This is also covered in the tutorial User Controls)

As a challenge to those of you who are already comfortable with styles and data-binding and who "don't need no stinkin' video" -- I've posted a broken version of the program for you to debug. <chortle>

bug

Your mission, should you decide to accept it, is to find the bug, and fix it.

In the video I show this broken version and why it is broken, and then I fix it;  but if you'd like to get ahead of the curve and try your hand... have at it. It's a bit sneaky.

What is supposed to happen when you run the app is that if you hit Control-C the address of the Computer Museum is filled in and if you hit Control-M the address of Microsoft is filled in.  But it don't. <cackle>

Published Thursday, May 01, 2008 11:04 AM by jesseliberty
Filed under:

Comments

# re: Silverlight Debugging Challenge

I added : INotifyPropertyChanged to the address class and now seems to be working

 is this correct or have I over complicated it ?

 

No; you got it. Thanks!  -jesse (I've obfuscaated your answer.)

Thursday, May 01, 2008 7:47 PM by sariel

# re: Silverlight Debugging Challenge

Hi Jesse,

I proposed this answer:

In AddressGrid_KeyDown, replace:

AddressGrid.DataContext = theAddress;

By:

if (!string.IsNullOrEmpty(theAddress.Address1) && !string.IsNullOrEmpty(theAddress.Address2) && !string.IsNullOrEmpty(theAddress.City) && !string.IsNullOrEmpty(theAddress.Location))

{

   AddressGrid.DataContext = theAddress;

}

Also, add a little code to allow the Location TextBox to have the focus on Loaded.

Am I right ?

Thanks !

Friday, May 02, 2008 3:05 AM by Thomas Lebrun

# Dew Drop - May 2, 2008 | Alvin Ashcraft's Morning Dew

Pingback from  Dew Drop - May 2, 2008 | Alvin Ashcraft's Morning Dew

# re: Silverlight Debugging Challenge

Thomas,

there is a much simpler fix. The biz object is getting updated (you can see that in the debugger) but when it is, nothing happens at the UI.

Saturday, May 03, 2008 4:29 PM by jesseliberty

# re: Silverlight Debugging Challenge

3 different options:

first one:

In AddressGrid_KeyDown:

if(e.Key == ....)

  AddressGrid.DataContext = new Address{Location="...}

This will indicate to the DataBinding system that a change occured on the DataContext property (as we reset it).

second one:

In Address.cs:

Implement INotifyPropertyChanged, to notify changes on individual properties

third one (but I don't know if it works in Silverlight, as I'm not aware of differents with WPF):

at the end of AddressGrid_KeyDown, call the Update method on the Binding itself.

Tuesday, May 06, 2008 8:56 AM by simon.ferquel