Silverlight 2 gotcha

I was going through an example from Microsoft’s Tim Sneath and hit the following error…
A first chance exception of type ‘System.Windows.Markup.XamlParseException’ occurred in System.Windows.dll
Additional information: AG_E_PARSER_BAD_PROPERTY_VALUE
 
I dread this sort of error in Silverlight, but it turns out that the answer in this case was fairly simple, if a little suprising. The example has 3 slider controls each sharing the same ValueChanged event handler. However, as the page is initialized the slider values are firing their ValueChanged events. Unfortunatley the shared event handler examines the value of all the controls but they are not yet available, hence the error. To avoid this I simply check for null in the event handler.
 
 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s