Próbuję napisać swoją pierwszą aplikacje w oparciu o MVVM. Natknąłem się na problem z bindowaniem kombinacji zdarzeń. Stan który mam obecnie:
<DockPanel Grid.Row="1" Margin="10" Visibility="{Binding IsReady, Converter={StaticResource InvertBoolToVisibilityConverter}}">
<ItemsControl Name="ICGameBoard" ItemsSource="{Binding Items}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="{Binding CountRows}" Columns="{Binding CountColumns}" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding Name}" Grid.Row="{Binding Row}" Margin="3"
Grid.Column="{Binding Column}" FontSize="25"
Background="{Binding State, Converter= {StaticResource EnumToBackgroundColorConverter}}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseEnter" >
<i:InvokeCommandAction
Command="{Binding ElementName=ICGameBoard, Path=DataContext.MouseEnterCommand}"
CommandParameter="{Binding}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DockPanel>
Działa to bez zarzutu: w momencie wjechanie kursora nad przycisk, wywołuje komendę ICGameBoard
z ViewModelu przekazując w parametrze obiekt zbindowany do przycisku.
Pytanie: jak zrobić w oparciu o MVVM kombinację zdarzeń, np. po wjechaniu kursora myszki nad przycisk i przy jednoczesnym kliknięciu prawym przyciskiem myszy wywołaj komendę ICGameBoard
?
"Normalnie", czyli bez bindowania zdarzeń i MVVM, zrobiłbym to tak:
<Button Content="Button" Width="74" MouseEnter="Button_MouseEnter"/>
private void Button_MouseEnter(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
MessageBox.Show("O to chodziło!");
}
}