初期化されたキャンバス上の単一の画像を新しい画像、pixelpainter / mapeditor スタイルに置き換えたいです。現在、MouseEnter の画像を置き換えることができますが、これは私の目標ではありません。ユーザーがマウスボタンを(おそらくMouseEnterで)画像の上に置いたときにのみ、画像を変更したいと思います。
<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>
このコードは、イベント "MouseEnter" でのみ機能します。ここでは、MouseDown や PreviewMouseDown を他のイベントと共に使用することはできません。これを回避するには、どの方法が最もクリーンでしょうか? EventToCommand と RelayCommand を保持したいと思います。
私の MainViewModel では、次のことだけを行います。
private RelayCommand<BitmapModel> _changeTileCommand;
public RelayCommand<BitmapModel> ChangeTilesCommand {
get { return _changeTileCommand ?? (_changeTileCommand = new RelayCommand<BitmapModel>(UpdateTile)); }
}
と
public void UpdateTile(BitmapModel tile) {
// BitmapModel tile = drag.TileParam;
if (tile == null) return;
if (SelectedMapTile == null) return;
tile.MapTileImage = SelectedMapTile.MapTileImage;
}