I am a bit confused about ICommand and RelayCommand
If I do this on an autocomplete control
public RelayCommand<KeyEventArgs> AutoCompleteCommand
{
get;
private set;
}
public MyConstructor()
{
AutoCompleteCommand = new RelayCommand<KeyEventArgs>((e) =>
{
//Check if the key pressed is <Enter>
//if it is, check also if the SearchPropertyValue is not String.Empty then
var d = e;
//Should it return true or false?
});
}
In the Xaml:
<toolkit:AutoCompleteBox x:Name="acbStore" Margin="154,196,29,0" VerticalAlignment="Top" RenderTransformOrigin="0.6,0.083" Height="162"/>
<i:Interaction.Triggers>
<i:EventTrigger EventName="KeyDown">
<GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding AutoCompleteCommand, Mode=OneWay}" PassEventArgsToCommand="True"/>
</i:EventTrigger>
</i:Interaction.Triggers>
Nothing happens.
If I do this
public ICommand AutoComplete
{
get
{
return new RelayCommand<KeyEventArgs>(e =>
{
var key = e.Key;
});
}
}
In the Xaml:
<i:Interaction.Triggers>
<i:EventTrigger EventName="KeyDown">
<GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding AutoComplete, Mode=OneWay}"
PassEventArgsToCommand="True"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<toolkit:AutoCompleteBox x:Name="acbStore" Margin="154,196,29,0"
VerticalAlignment="Top" RenderTransformOrigin="0.6,0.083" Height="162"/>
It works and my command is triggered.
Also from all the examples I seen the RelayCommand always seems to go in the constructor. Can I stick it anywhere else as it is going to make the constructor very cluttered.