画像を表示するボタンがあります:
<Button Command="{Binding Model.ZoomOnImage}">
<Image Source="{Binding Model.ImageSource}" Stretch="Uniform" />
</Button>
私のModelクラスには、次のコマンドがあります。
private ICommand _zoomOnImage;
public ICommand ZoomOnImage
{
get
{
if (_zoomOnImage == null)
_zoomOnImage = new RelayCommand(Zoom, CanZoom);
return _zoomOnImage;
}
}
private void Zoom() {...}
private bool CanZoom() {...}
ユーザーがボタンをクリックしたときに、[X; Y]座標(実行するZoom(int X, int Y)
)。これを実現するためにコードを変更するにはどうすればよいですか?
必要に応じて、カスタムボタンを使用するか、ビヘイビアを作成します。ビューモデルにプロパティも追加しますpublic Point MousePosition{get;set;}
<local:CustomButton Command="{Binding Model.ZoomOnImage}" MousePosition="{Binding MousePosition}">
<Image Source="{Binding Model.ImageSource}" Stretch="Uniform" />
</local:CustomButton>
public class CustomButton : Button
{
public Point MousePosition
{
get { return (Point)GetValue(MousePositionProperty); }
set { SetValue(MousePositionProperty, value); }
}
// Using a DependencyProperty as the backing store for MousePosition. This enables animation, styling, binding, etc...
public static readonly DependencyProperty MousePositionProperty = DependencyProperty.Register("MousePosition", typeof(Point), typeof(CustomButton), new FrameworkPropertyMetadata(new Point(), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
protected override void OnClick()
{
base.OnClick();
MousePosition = Mouse.GetPosition(this);
}
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加