0

初期化されたキャンバス上の単一の画像を新しい画像、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;
        }
4

2 に答える 2

0

ボタンで非常に簡単な回避策を実行できます。画像をボタンに挿入し、プロパティCommandCommandParameterプロパティを使用するだけです。しかし、これはイベントでのみ発生しLeftMouseButtonUpます!

<Button Margin="100" BorderThickness="0" 
        Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
        Command="..." 
        CommandParameter="...">
    <Image Source="..." Stretch="Fill" 
           Width="{Binding Width}" 
           Height="{Binding Height}" />
</Button>

ボタンは「何もない」ように見えるはずなので、ボタンのビジュアルを少し調整する必要があります。境界線を削除してこれを行い、Styleプロパティを介してフラット スタイルに設定しました。この質問は、ボタンのスタイルを少し良くするのに役立つかもしれません。

于 2015-11-30T15:25:15.360 に答える