开发者

Setting the background color on a Silverlight grid and still being able to edit it

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.Ce开发者_JS百科llEditingTemplate>
                            <DataTemplate>
                                <TextBox Background="Cornsilk" Text="{Binding Path=LongTermRank, Mode=TwoWay}" />
                            </DataTemplate>
                        </data:DataGridTemplateColumn.CellEditingTemplate>
                    </data:DataGridTemplateColumn>


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜