I’m presenting at the Twin Cities Silverlight User Group today. We had to shift gears at the last minute and change our plan for the event. So the day before leaving for vacation I decided that I would present a topic at the user group, which would leave me only one day to prepare for the presentation when I returned, which happened to be my wedding anniversary (sorry honey).
Luckily I had already written some code to demonstrate binding using converters, and it only took a few hours (although very hurried) to turn it into a step by step presentation.
Here is a tiny little Silverlight 2 project that has several nice binding and converter lessons in it. As I said, I felt a bit rushed, so there could be some minor issues I missed. If you hit one, and can’t get around it, send me an email. If you are visiting this site after having attended the user group, and want the starting point of this project, send me an email and I’ll reply with the two files we started with at the beginning of the demo.
Here are some of the highlights this project shows:
A simple one-way converter for color that uses an int input to make a solid color brush
A simple one-way converter that inputs anything (including whole objects) and returns Visibility.Collapsed if the object is null or empty string
A complex two-way converter solutions for binding to combo boxes
Examples of a view model that uses some display properties and examples of notifying on multiple properties if you used display (read-only) properties
Examples of using a different property to sort a datagrid column to avoid null pointer exception (missing Spouse, in the example) or to sort by a different value (month number instead of month name)
Using the SelectedItem of a grid to drive the data context for an edit form, which has immediate updates back to grid
Get the Code