我的Canvas中有一些自定義控件。在WPF中區別選擇和拖動
該控件可以通過拖放來移動,也可以通過單擊進行選擇。現在
,我實現拖放是這樣的:
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnPreviewMouseLeftButtonDown(e);
this.isDragInProgress = false;
// Cache the mouse cursor location.
this.origCursorLocation = e.GetPosition(this);
// Walk up the visual tree from the element that was clicked,
// looking for an element that is a direct child of the Canvas.
var source = e.Source;
var element = this.FindCanvasChild(source as DependencyObject);
if (element == null || !(element is MyControl))
return;
this.ElementBeingDragged = element;
// Get the element's offsets from the four sides of the Canvas.
this.draggedLeft = Canvas.GetLeft(this.ElementBeingDragged);
this.darggedTop = Canvas.GetTop(this.ElementBeingDragged);
// Set the Handled flag so that a control being dragged
// does not react to the mouse input.
e.Handled = true;
this.isDragInProgress = true;
}
現在,我的問題是,我無法選擇它MyControl點擊......(沒有鼠標點擊事件上的自定義控制,也不MouseDown現在的作品..)
如果我會評論e.Handled = true;
控制將改變它的選擇拖動時,如果不評論它,控制將不會改變它的選擇......(