I was previously using the Telerik EventToCommandBehavior to capture the double-click event for my GridView, but as others have discovered I had the issue that it also triggered when a user clicked on the scrollbar quickly:
<
telerik:EventToCommandBehavior.EventBindings
>
<
telerik:EventBinding
EventName
=
"MouseDoubleClick"
Command
=
"{Binding ShowEditWindowCmd}"
CommandParameter
=
"{Binding SelectedItem, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type telerik:RadGridView}}}"
/>
</
telerik:EventToCommandBehavior.EventBindings
>
So now I've switched over to another solution using the code-behind, but it feels like it breaks the MVVM model too much in my case. I realize I'm splitting hairs because this does what I want, but is there maybe a better (cleaner) way to do this? I would love to use the EventToCommandBehavior on the row, but couldn't figure out how.
public
partial
class
PackageBoardsGrid : UserControl
{
PackageBoardsPage pageVM;
public
PackageBoardsGrid()
{
InitializeComponent();
this
.DataContextChanged += ( o, e ) =>
{
if
( e.NewValue
is
PackageBoardsPage )
pageVM = (PackageBoardsPage)e.NewValue;
};
}
private
void
Grid_RowLoaded(
object
sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e )
{
if
( e.Row
is
GridViewRow ) {
e.Row.AddHandler(GridViewRow.MouseDoubleClickEvent,
new
MouseButtonEventHandler(OnRowMouseDoubleClick),
true
);
}
}
private
void
OnRowMouseDoubleClick(
object
sender, MouseButtonEventArgs args )
{
if
( pageVM !=
null
) {
var gridViewRow = sender
as
GridViewRow;
if
( gridViewRow !=
null
) {
var data = gridViewRow.DataContext
as
LiveBoard;
if
( data !=
null
)
pageVM.ShowEditWindowCmd.Execute(data);
}
}
}
}