locked
is it possible to disable a gesture on a datagrid? RRS feed

  • Question

  • I have a datagrid and I would like to disabled all the gestures of it. I have this on:

    <DataGrid.InputBindings> <MouseBinding Gesture="LeftDoubleClick" Command="{Binding DatagridMouseDoubleClickCommand}" CommandParameter="{Binding ElementName=datagrid, Path=SelectedItems, Mode=OneWay}"/> <KeyBinding Key="Enter" Command="{Binding DatagridMouseDoubleClickCommand}" CommandParameter="{Binding ElementName=datagrid, Path=SelectedItems, Mode=OneWay}" /> </DataGrid.InputBindings>

    In the commands (I am using MVVM Light) I have the property IsEnabled, so I can avoid the execution of the command if it is disabled, but in the gestures I don't have this option, so I would like to know if there is any way to do it.

    I have tried to disabled the datagrid, but then the event selectionChanged and other events are not fired when the datagrid is disabled, so this is not a relly good solution in my case.

    Thanks so much.

    Wednesday, January 28, 2015 3:29 PM

Answers

  • Aren't you using mvvmlight relaycommands?

    They have the canexecute mechanism.

    FooCommand = new RelayCommand(() => FooExecute(), () => CanFoo());
    When Canfoo returns false anything bound to the command is isenabled=false


    Please don't forget to upvote posts which you like and mark those which answer your question.
    My latest Technet article - Dynamic XAML

    Wednesday, January 28, 2015 3:40 PM