views:

12

answers:

1

how can i programmatically binding images to silverlight datagrid cell of a particular column based on the datasource values

A: 

Use an implementation of IValueConverter that I blog about here. I'll assume for the moment (your question lacks detail so I'll make some up) that you have some kind of property that exposes an enum of a finite set of states.

In your case the value converter will contain a ResourceDictionary of BitmapImage entries:-

        <local:StringToObjectConverter x:Key="StatusToIcon">
            <ResourceDictionary>
                <BitmapImage UriSource="/Assets/State1.png" x:Key="State1" />
                <BitmapImage UriSource="/Assets/State2.png" x:Key="State2" />
                <BitmapImage UriSource="/Assets/UnknownState.png" x:Key="__default__" />
            </ResourceDictionary>
        </local:StringToObjectConverter>   

In the template for your cell you would use:-

<Image Source="{Binding State, Converter={StaticResource StatusToIcon}}" />
AnthonyWJones