I have a code snippet as below:
XAML
...
<DataGrid>
<i:Interaction.Triggers>
<i:EventTrigger EventName="PreviewKeyDown">
<mvvm:EventToCommand Command="{Binding KeyDownLocationDG}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</DataGrid>
ViewModel
public class A
{
public RelayCommand<KeyEventArgs> KeyDownLocationDG { get; set; }
public A()
{
KeyDownLocationDG = new RelayCommand<KeyEventArgs>(TestMethod);
App.processBarcodeData = new App.ProcessBarCodeData((barcode) =>
{
DoSomething();
// then I ONLY want to trigger KeyDownLocationDG command here
});
}
private void TestMethod(KeyEventArgs e)
{
...
}
}
I also have a MainWindow.xaml file, there is a KeyPressed
event of RawPresentationInput
object in the code-behind (MainWindow.xaml.cs). Everytime this event fired, I'll call processBarcodeData
delegate. If I press a key on DataGrid, the TestMethod
will be executed immediately, but I don't want to do that, what I want is to make it can only run after DoSomething() done.
Can someone help me? Thanks.