开发者

Silverlight DataGrid cells disappearing

I've got a DataGrid in a Silverlight application with data in it. There's also a button on our app that can change the layout such that the DataGrid changes width.

The problem is when you are in the "small" mode and scroll around, for columns that you can't see, their DataGridCell elements get Visibility=Collapsed. Now this is fine when you are scrolling around, but when the size of the DataGrid increases to show all columns, they stay collapsed. However for some reason you can always see all the cells in the first row.

This smells like a bug in the DataGrid control. Does anyone know a way to work around it? I've got as far as adding a handler for SizeChanged on the DataGrid, but I'm not quite sure what to call to force it to show those collapsed cells.

EDIT: After some testing I've found that it only happens with GridLinesVisibility="Horizontal"

XAML (Clicking toggles width of DataGrid from half to full):

<StackPanel Orientation="Vertical">
    <data:DataGrid x:Name="testDataGrid" GridLinesVisibility="Horizontal" />
    <Button HorizontalAlignment="Center" Content="Switch Width" Name="switchWidthButton" Click="Button_Click" />
</StackPanel>

Update: Though it can still happen sometimes with GridLinesVisibilty not set. I have not worked out exactly what开发者_开发问答 circumstances this happens under.


After some discussion on the MS alias I've found that it is in fact a bug in the DataGrid. I've sent them a repro project so hopefully it will be fixed in the future. In the meantime as a workaround, you can hide and re-show one of the columns when the DataGrid changes size:

<data:DataGrid x:Name="testDataGrid" GridLinesVisibility="Horizontal" Width="150" SizeChanged="testDataGrid_SizeChanged" />

-

private void testDataGrid_SizeChanged(object sender, SizeChangedEventArgs e)
{
    this.testDataGrid.Columns[0].Visibility = Visibility.Collapsed;
    this.testDataGrid.Columns[0].Visibility = Visibility.Visible;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜