2009-12-22 5 views
0

Lesters DragAndDropManager 내 응용 프로그램에서 끌어서 놓기 기능을 사용하고 있으며 실제로 구현 된 방식이 마음에 들지만 한 가지 작은 문제가있어서 그 것을 보여주고 싶습니다. 내 상태 표시 줄에서 드래그하는 동안 마우스 코드를 지정하면 DropManager의 마우스 위치를 내 xaml 코드로 어떻게 보내야합니까?WPF에서 드래그 앤 드롭을 할 때 mousepoint를 표시

xaml-code에서 바인드 할 수있는 관리자에 dependencyproperty를 추가하려고했습니다.

public static readonly DependencyProperty MousePointProperty = 
     DependencyProperty.RegisterAttached("MousePoint", typeof(Point), typeof(DragDropBehavior), 
     new FrameworkPropertyMetadata(default(Point))); 
    public static void SetMousePoint(DependencyObject depObj, bool isSet) 
    { 
     depObj.SetValue(MousePointProperty, isSet); 
    } 
    public static IDragSourceAdvisor GetMousePoint(DependencyObject depObj) 
    { 
     return depObj.GetValue(MousePointProperty) as IDragSourceAdvisor; 
    } 

그리고 Xaml에서 나는 이와 같이 바인딩합니다.

<StatusBar> 
     <TextBlock Text="{Binding local:DragDropBehavior.MousePoint.X}"/> 
    </StatusBar> 

하지만 어떻게 mousecordintation을 관리자의 dependecyproperty로 설정합니까?

private static void DropTarget_PreviewDragOver(object sender, DragEventArgs e) 
    { 
     if (UpdateEffects(sender, e) == false) return; 
     //-- Update position of the preview Adorner 
     Point position = GetMousePosition(sender as UIElement); 

     //-- Here I Want to do this, but that not posible because the SetMousePoint takes a dependencyObject and not my value. 
     //-- SetMousePoint(position); 

     _draggedUIElementAdorner.Left = position.X - _offsetPoint.X; 
     _draggedUIElementAdorner.Top = position.Y - _offsetPoint.Y; 

     e.Handled = true; 
    } 

나는 내가 잘못 여기라고 생각하지만, 나는 DragAndDropManager에 결합하여 XAML 코드에 mousecordination을 얻는 방법에 박히있다.

감사합니다.

답변

1

정확히. 첨부 된 객체를 알아야하기 때문에 원하는 방식으로 연결된 속성에 바인딩 할 수 없습니다.

어떻게 하시겠습니까? 세 가지 옵션이 있습니다 (그러나 더 많은 옵션이 있습니다).

  1. 드래그 할 때마다 사용자 지정 상태 표시 줄 클래스에서 전역 마우스 이벤트 수신기 (Mouse.MouseMoveEvent)를 사용하십시오.
  2. 정적 이벤트를 DragAndDropManager에서 노출 시키십시오. 사용자 정의 상태 표시 줄 클래스에서 구독하십시오. 드래그가 발생할 때마다 DragAndDropManager에서 이벤트를 실행하십시오. 그러나 정적 이벤트에주의하십시오. 메모리 누수를 도입하는 것은 매우 쉽습니다 ...
  3. DragAndDropManager을 싱글 톤으로 변환하십시오. INotifyValueChanged를 구현하고 인스턴스 속성 MousePoint을 만듭니다. =

    텍스트 : 상태 표시 줄에서 바인딩 "{, 소스가 = {X MousePoint.X 바인딩 : 정적 지역 : DragDropBehavior.Instance}}"드래그가 발생할 때마다

는, 인스턴스 속성을 업데이트하고, 인상 속성이 변경되었습니다. 이 도움이

희망,

건배, Anvaka

관련 문제