Search code examples
wpfxamlinputdata-bindinggesture

How can i add a behavior of long presion of shortcut?


My inputbinding is something like that :

 <KeyBinding Key="S" Modifiers="Ctrl" Command="{Binding NewCommand}"/>

I want to add a delay for this command. For example, i would to hold down my two buttons 3sec and after the command run.

Thanks,


Solution

  • You can do this in ViewModel using Thread.Sleep

    public class MainWindowViewModel
    {
        public RelayCommand NewCommand { get; set; }
    
        public MainWindowViewModel()
        {
            NewCommand = new RelayCommand(Command);
        }
    
        private void Command(object parameter)
        {
            Thread.Sleep(3000);
    
            MessageBox.Show("Hello World");
        }
    }