Hello,
i am trying to implement a command (LeftDoubleClick) from my view to viewmodel using mvvm pattern (without code behind and event).
I saw some samples but they don't work for me!
Please can someone tell me i i am making wrong?
xaml:
<telerik:RadGridView x:Name="radGridView" Margin="8" ItemsSource="{Binding Source={StaticResource DataSource}}" IsReadOnly="True" > <telerik:RadGridView.InputBindings> <MouseBinding Gesture="LeftDoubleClick" helpers:AttachedMouseBinding.Command="{Binding Path=DoubleClickCommand}" /> </telerik:RadGridView.InputBindings> </telerik:RadGridView>
.cs:
public class UC_SEGridViewModel : InterfaceDescription.ViewModels.ViewModelBase{ private ViewModelMaster viewModelMaster; public ICommand DoubleClickCommand { get; set; } public UC_SEGridViewModel() { DoubleClickCommand = new RelayCommand(GridItemDoubleClick); } private void GridItemDoubleClick(object obj) { //do something }}but i don't reach my callback method (GridItemDoubleClick) when i set a breackpoint
the helper:
public class AttachedMouseBinding { const string PROPERTYNAMECOMMAND = "Command"; public static readonly DependencyProperty CommandProperty = DependencyProperty.RegisterAttached(PROPERTYNAMECOMMAND, typeof(ICommand), typeof(AttachedMouseBinding), new FrameworkPropertyMetadata(CommandChanged)); private static void CommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { FrameworkElement fe = d as FrameworkElement; ICommand command = e.NewValue as ICommand; InputBinding inputBinding = new InputBinding(command, new MouseGesture(MouseAction.LeftDoubleClick)); fe.InputBindings.Add(inputBinding); //if (inputBinding != null) // inputBinding.Command = command; } public static ICommand GetCommand(DependencyObject obj) { return (ICommand)obj.GetValue(CommandProperty); } public static void SetCommand(DependencyObject obj,ICommand value) { obj.SetValue(CommandProperty, value); } }
Thanks for your help,
Richard