Archives

Archives / 2009 / January
  • Conditional Formatting in the Silverlight DataGrid

    I’ve been an asp.net developer for some time now and I was excited to jump on to Silverlight when it 2.0
    was released a few months ago.  One thing I really struggled with was applying conditional formatting to
    the individual cells in the DataGrid control.  Coming from an asp.net background, I carried a lot of
    assumptions with me (big mistake).  I thought I could get a hold of the rows or cells collection and have
    my way with it, but no such luck.  I stumbled down several paths which all ultimately lead to dead ends. 
    After killing hours (maybe days) on trying to figure this out, I had to let it go and move on.  Now a month
    later I decided to give it another shot and I finally got it.  The answer was right in front of me all along. 
    I knew about the IValueConverter interface, but I didn’t fully understand its capabilities.  I thought it was
    only used for converting an object into a text representation or vice versa.  Actually, you can return
    anything you want from it.  So you can return a Button, Grid, or whatever.