XAMLファイルのWPFでマウスの位置にバインドする方法はありますか?それとも、コードで行う必要がありますか?Canvas内にコントロールがあり、マウスカーソルがCanvas内にある間、コントロールをマウスに追従させたいだけです。
ありがとう
編集:
OK、コードビハインドファイルを使用して比較的簡単な方法を見つけました。CanvasにMouseMoveイベントハンドラーを追加してから、次を追加しました。
private void Canvas_MouseMove(object sender, MouseEventArgs e)
{
// Get the x and y coordinates of the mouse pointer.
System.Windows.Point position = e.GetPosition(this);
double pX = position.X;
double pY = position.Y;
// Sets the position of the image to the mouse coordinates.
myMouseImage.SetValue(Canvas.LeftProperty, pX);
myMouseImage.SetValue(Canvas.TopProperty, pY);
}
ガイドラインとしてhttp://msdn.microsoft.com/en-us/library/ms746626.aspxを使用します。