我有一些行和列的WPF Grid
,例如
<Grid Name="myGrid" MouseMove="OnMouseMove">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
</Grid>
在.cs文件中使用
MouseMove
的处理程序,例如private void OnMouseMove(object sender, MouseEventArgs e)
{
var position = e.GetPosition(myGrid);
// What row & col is the mouse over?
}
我希望能够找到鼠标悬停在网格中的行和列,这可能吗?
[注意:这是问题的简化版本,因此以这种方式呈现它看起来有些奇怪-它是网格功能之间某些拖放的一部分]
最佳答案
希望您已经找到了解决方案。我遇到了同样的问题,却发现了这个未答复的帖子。因此,我认为下一个将很乐意找到此解决方案:
private void OnMouseMove(object sender, MouseEventArgs e)
{
var element = (UIElement)e.Source;
int c = Grid.GetColumn(element);
int r = Grid.GetRow(element);
}
关于wpf - 在WPF网格中,如何在鼠标位置找到“行和列”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1259606/