I want to replace single images on a initialized canvas with new images, pixelpainter / mapeditor style. Currently I manage to replace images on MouseEnter but this isn't my goal. I only want to change the image when the user has his mousebutton down (maybe with MouseEnter) above a image.
<DataTemplate>
<Image Source="{Binding MapTileImage}" Stretch="Fill" Width="{Binding Width}" Height="{Binding Height}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseEnter">
<command:EventToCommand Command="{Binding RelativeSource={RelativeSource AncestorType=Window}, Path=DataContext.ChangeTilesCommand}" CommandParameter="{Binding .}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Image>
</DataTemplate>
This code works only with the event "MouseEnter". MouseDown and even PreviewMouseDown along with other events do not work here. Which way would be the cleanest to get around this? I'd like to keep my EventToCommand and RelayCommand.
In my MainViewModel all I do is:
private RelayCommand<BitmapModel> _changeTileCommand;
public RelayCommand<BitmapModel> ChangeTilesCommand {
get { return _changeTileCommand ?? (_changeTileCommand = new RelayCommand<BitmapModel>(UpdateTile)); }
}
with
public void UpdateTile(BitmapModel tile) {
// BitmapModel tile = drag.TileParam;
if (tile == null) return;
if (SelectedMapTile == null) return;
tile.MapTileImage = SelectedMapTile.MapTileImage;
}