views:

591

answers:

2

The first column below works perfectly except I can't set the background color. The second column has the background color working most of the way except when using the arrow keys to move around in the grid, the cell isn't visually changing. What is the easiest way to just change the gosh darn background color on a text column? Extra points if there is a way to do it without going into the template column and exploding the lines of code so much.

                    <data:DataGridTextColumn
                        Header="Rank ST" 
                        Binding="{Binding Path=ShortTermRank}" 
                        IsReadOnly="False"
                    />

                    <data:DataGridTemplateColumn Header="Rank LT">
                        <data:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Border Background="Cornsilk">
                                    <TextBlock Text="{Binding Path=LongTermRank}" Margin="4" />
                                </Border>
                            </DataTemplate>
                        </data:DataGridTemplateColumn.CellTemplate>
                        <data:DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate>
                                <TextBox Background="Cornsilk" Text="{Binding Path=LongTermRank, Mode=TwoWay}" />
                            </DataTemplate>
                        </data:DataGridTemplateColumn.CellEditingTemplate>
                    </data:DataGridTemplateColumn>
A: 

Setting the opacity slightly lower works reasonably well and I don't have to mess with events or anything. I'm going to create a custom column type that will allow this to be resued as well, IMO this should be in the toolkit, setting the background color hsouldn't be such a chore.

                    <data:DataGridTemplateColumn Header="Rank LT" SortMemberPath="LongTermRank">
                        <data:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Grid>
                                    <Border Background="Cornsilk" Opacity=".5" />
                                    <TextBlock Text="{Binding Path=LongTermRank}" Margin="4" />
                                </Grid>
                            </DataTemplate>
                        </data:DataGridTemplateColumn.CellTemplate>
                        <data:DataGridTemplateColumn.CellEditingTemplate>
                            <DataTemplate>
                                <TextBox Background="Cornsilk" Text="{Binding Path=LongTermRank, Mode=TwoWay}" />
                            </DataTemplate>
                        </data:DataGridTemplateColumn.CellEditingTemplate>
                    </data:DataGridTemplateColumn>
Paul B.