Silverlight 3 Datagrid:在MouseOver上获取行/项 [英] Silverlight 3 Datagrid: Get row/item on MouseOver

查看:163
本文介绍了Silverlight 3 Datagrid:在MouseOver上获取行/项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个绑定的DataGrid和各种其他控件(在datagrid外部),显示有关datagrid中的被选中的更多细节。这很容易在数据绑定或处理Datagrid上的SelectionChanged事件。



但是,如何在不需要用户选择行的情况下执行此操作 - 例如鼠标悬停我可以更改所选项目,或者获取鼠标下的行/项目。

解决方案

吉姆答案的通用性较差。在VB.Net中:

  Private Sub DataGrid1_LoadingRow(ByVal sender As Object,ByVal e As System.Windows.Controls.DataGridRowEventArgs)句柄DataGrid1.LoadingRow 
AddHandler e.Row.MouseEnter,AddressOf row_MouseEnter
End Sub

Private Sub row_MouseEnter(ByVal sender As Object,ByVal e As MouseEventArgs)
Dim row = CType(sender,DataGridRow)
Me.DataGrid1.SelectedItem = CType(row.DataContext,MyType)
End Sub


I have a bound DataGrid and various other controls(external to the datagrid) that show more details about the selectedrow in the datagrid. This is easy to do with databinding or handling the SelectionChanged event on the datagrid.

However, how do I do this without requiring the user to select a row - eg on 'mouseover' can I change the selected item or get the row/item 'under' the mouse.

解决方案

Here is a simpler but less generic implementation of Jim's answer. In VB.Net:

Private Sub DataGrid1_LoadingRow(ByVal sender As Object, ByVal e As System.Windows.Controls.DataGridRowEventArgs) Handles DataGrid1.LoadingRow
    AddHandler e.Row.MouseEnter, AddressOf row_MouseEnter
End Sub

Private Sub row_MouseEnter(ByVal sender As Object, ByVal e As MouseEventArgs)
        Dim row = CType(sender, DataGridRow)
        Me.DataGrid1.SelectedItem = CType(row.DataContext, MyType)
End Sub

这篇关于Silverlight 3 Datagrid:在MouseOver上获取行/项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆