开发者

WPF Datagrid misbehaving on selected row

I have the standard WPF DataGrid defined in a custom control. When I click on a cell in the grid the whole row is highlighted in blue which is what I want. The trouble is that when I click on some other page in the app and then come back to the grid, when I click on a cell on the grid only that cell gets selected and not the whole row as before.

Anyone any idea why this might be happening? The WFP control is part of a Winforms app and is a part of a winform tab control, when i click on a different tab and then return to the tab with the WPF control on it I get the problem.

This is how I define the DataGrid:

<Grid>                        
    <my:DataGrid x:Name="dataGridBackup" ItemsSource="{Binding}" AutoGenerateColumns="False"
  开发者_StackOverflow中文版               GridLinesVisibility="All" IsReadOnly="True">
        <my:DataGrid.Columns>
            <my:DataGridTextColumn Header="Name" Binding="{Binding Name}" />
            <my:DataGridCheckBoxColumn Header="Connectable" Binding="{Binding Connectable}"  />
            <my:DataGridTextColumn Header="Product" Binding="{Binding Product}" Width="*" />
            <my:DataGridTextColumn Header="Collation" Binding="{Binding Collation}"  />
        </my:DataGrid.Columns>
    </my:DataGrid>
</Grid>


I think I have a solution for your problem. Sometimes DataGrid behaves this way. The best way as far as I know is to explicitly set the SelectionUnit.

<my:DataGrid SelectionUnit="FullRow" >

</my:DataGrid>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜