views:

144

answers:

1

Hi all.

I have a converter that returns a background colour based on a binding value on a DataGrid. This is working great in WPF but when i put this code into silverlight it is not happy.

Reading some posts on here it seems i can not use TargetType="{x:Type my:DataGridCell}" The answer suggested was to use simply TargetType="my:DataGridCell" but again this did not work.

Another suggestion was to give the style a Key but as my style is set on my DataGrid i can not move this to Page.Resources (and thus give it a key) as i need to bind to it. Like so:

    <data:DataGrid x:Name="gridResults" CanUserReorderColumns="True" HorizontalAlignment="Left" IsReadOnly="True" AutoGenerateColumns="False" SelectionChanged="gridResults_SelectionChanged" ItemsSource="{Binding}">
        <data:DataGrid.CellStyle>
            <Style TargetType="{x:Type data:DataGridCell}">
                <Setter Property="Background" Value="{Binding SoldIn, Converter={StaticResource conFor}}" />
            </Style>
        </data:DataGrid.CellStyle>
            <data:DataGrid.Columns>
            <data:DataGridTextColumn
                     Header="Outlet"
                     Width="Auto"
                     Binding="{Binding Outlet}" />
   ....
   ....

How can i keep my binding in tact and make silverlight be happy?

Thanks, Kohan

A: 

Not the perfect solution but i got my desired results though using data:DataGridTemplateColumns instead.

            <data:DataGridTemplateColumn Header="Outlet">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <Border Background="{Binding SoldIn, Converter={StaticResource conFor}}">
                            <ContentControl Content="{Binding Outlet}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" />
                        </Border>
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>
Kohan