2014-01-14 2 views
0

요소를 클릭하고 마우스 버튼을 누른 상태에서 DragMove를 트리거하는 데 사용되는 요소가 XAML에 있습니다.DragMove 다음에 MouseLeftButtonUp이 호출되지 않습니다.

<Grid> 
    <CheckBox x:Name="myCheckBox" IsChecked="{Binding IsDragging}">I am red square dragging!</CheckBox> 
    <Rectangle x:Name="myRect" Width="100" Height="100" Fill="Red"/> 
</Grid> 

이벤트 처리는 다음과 같은 방법으로 코드 숨김 수행됩니다

protected override void OnInitialized(EventArgs e) 
    { 
     base.OnInitialized(e); 

     myRect.MouseLeftButtonDown += myRect_MouseLeftButtonDown; 
     myRect.MouseLeftButtonUp += myRect_MouseLeftButtonUp; 
    } 

    void myRect_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) 
    { 
     IsDragging = false; 
    } 

    void myRect_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) 
    { 
     IsDragging = true; 
     DragMove(); 
    } 

true로 설정 한 후 IsDragging false로 설정되지 않습니다 그래서 심지어 작품을 드래그하지만, myRect_MouseLeftButtonUp가 호출되지 않습니다. 이 작업을 어떻게 수행합니까?

보너스로,이 질문에 답하기 위해 동축 케이블을 사용하는 요소의 이미지가 있습니다.

enter image description here

답변

-1

DragMove이하는 MouseLeftButtonUp로 끝나는 차단 이벤트입니다. 올바른 동작은 참고

void myRect_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) 
    { 
     IsDragging = true; 
     DragMove();    
     myRect.RaiseEvent(new MouseButtonEventArgs(e.MouseDevice, e.Timestamp, MouseButton.Left) 
     { 
      RoutedEvent = MouseLeftButtonUpEvent 
     }); 
    } 

을 사용하여 유도 될 수 C# WPF - DragMove and click

관련 문제