如果要定位具体是哪个单元格,那可以
void ImageMouseDown(object sender, MouseButtonEventArgs e)
{
if (sender is Image)
{
Image image = sender as Image
// 以下是Image控件所处Grid的行和列
int RowIndex = Grid.GetRow(image)
int ColumnIndex = Grid.GetColumn(image)
// 也可以在这里更换图片
image.Source = ....
}
}
解决方法:鼠标事件并不是在column-by-column基础上进行处理的。相反,你应该处理GridView的双击事件,并构建一个GridHitInfo对象以确定双击事件在哪一列开始。事件处理程序的sender参数只可以被转换为GridView类型。[C#]
//Assign a double click handler
gridView1.DoubleClick += new EventHandler(gridView1_DoubleClick)
private void gridView1_DoubleClick(object sender, EventArgs e)
{
GridView detailGrid = (sender as GridView)
GridHitInfo hitInfo = (detailGrid.CalcHitInfo((e as MouseEventArgs).Location)
//Leave if the user didn't double-click in a cell
if (hitInfo.InRowCell == false)
return
//Leave if the user didn't double-click in the "Person Name" column
if (hitInfo.Column != detailGrid.Columns["PersonName"])
return
//Do something else
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)