WPF Datagrid 在选定行上行为不当
我在自定义控件中定义了标准 WPF DataGrid
。当我单击网格中的一个单元格时,整行都会以蓝色突出显示,这就是我想要的。问题是,当我单击应用程序中的其他页面然后返回网格时,当我单击网格上的某个单元格时,只会选择该单元格,而不是像以前那样选择整个行。
有人知道为什么会发生这种情况吗? WFP 控件是 Winforms 应用程序的一部分,也是 winform 选项卡控件的一部分,当我单击不同的选项卡,然后返回到带有 WPF 控件的选项卡时,我遇到了问题。
这就是我定义 DataGrid 的方式:
<Grid>
<my:DataGrid x:Name="dataGridBackup" ItemsSource="{Binding}" AutoGenerateColumns="False"
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 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"
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我有办法解决你的问题。有时 DataGrid 会以这种方式运行。据我所知,最好的方法是显式设置 SelectionUnit。
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.