I'm writing some app in WPF using mvvm pattern (so no code-behind). I have an ObservableCollection myCol. Objects are added dynamically into it (say by clicking on some button) The MyClass object contain a WritableBitmap mySource, that I'm using to draw an image.
I want to catch mouse down events on the items of myCol. My problem is that I need to have the item, on which the event was invoked and the position of the event - so two args. I'm using myConverter to pass both of the arguments. And that's my problem - I don't know how to pass the MouseButtonEventArgs to the multi converter.
Any solutions?
code in xaml:
<ItemsControl ItemsSource="{Binding myCol}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Image Source="{Binding mySource}">
<b:Interaction.Triggers>
<b:EventTrigger EventName="MouseDown">
<b:InvokeCommandAction Command="{Binding DataContext.MouseDownCommand, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}">
<b:InvokeCommandAction.CommandParameter>
<MultiBinding Converter="{StaticResource MyConverter}">
<Binding />
<!-- THE LINE BELOW HAS TO BE CHANGED -->
<Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type ItemsControl}}"/>
</MultiBinding>
</b:InvokeCommandAction.CommandParameter>
</b:InvokeCommandAction>
</b:EventTrigger>
</b:Interaction.Triggers>
</Image>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
and the Convert fun from myConverter:
public object Convert(object[] values, Type target_Type, object parameter, CultureInfo culture)
{
var myClass = (MyClass)values[0];
var args = (MouseButtonEventArgs)values[1]; // THAT I WANT
return new Tuple<MyClass, MouseButtonEventArgs>(myClass, args);
}