I want to use command to realize the KeyDown Event in textbox,
I wnat to let the command can recognize which key input such as KeyEventArgs do in KeyDown Event and do some other things,
So I want to pass command parameter into ReactiveCommand (just like Eventargs do in Event Method),
but I don't know how to do it.
I have WPF Xaml code :
<Window x:Class="NameSpaceTest.OpenFileW"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:command="http://www.galasoft.ch/mvvmlight"
Title="OpenFileWVieModel" Height="50" Width="200" WindowStyle="None">
<Grid>
<TextBox Name="Box" Text="{Binding OpenFPth, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="KeyDown">
<i:InvokeCommandAction Command="{Binding OpenFCmd}" CommandParameter=""/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
</Grid>
</Window>
and two class code first is the view, second the viewmodel:
public partial class OpenFileW : Window
{
OpenFileWVieModel OFVM = new OpenFileWVieModel();
public OpenFileW()
{
this.DataContext = OFVM;
InitializeComponent();
}
}
public class OpenFileWVieModel : ReactiveObject
{
public string OpenFPth { get { return _openFpth; } set { this.RaiseAndSetIfChanged(ref _openFpth, value); } }
private string _openFpth;
public IReactiveCommand OpenFCmd { get; set; }
public OpenFileWVieModel()
{
var TextChange = this.WhenAny(
x => x.OpenFPth,
x =>
{
MessageBox.Show("HI");
return true;
});
OpenFCmd = ReactiveCommand.CreateAsyncTask(
TextChange, //CanExecute
async _ =>//Execute
{
MessageBox.Show("HI");
}
);
}
}
What to do next to pass the textbox KeyInput as parameter to the command?