2017-02-06 13 views
1

이벤트 처리를 위해 WPF, MVVM 및 비헤이비어를 사용하는 데스크톱 응용 프로그램을 수정해야합니다. 단추를 놓기 위해 드래그 & 놓기를 구현하는 작업이 있습니다. 사용자가 버튼을 누르면 파일 저장 윈도우가 팝업되지만 사용자가 클릭하여 드래그하면 파일 아이콘이 표시되고 사용자가 Explorer 창에 파일 아이콘을 저장하면 저장됩니다.비헤이비어로 드래그 앤 드롭 추가

이미 추가 한 네임 스페이스 :

xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
xmlns:behaviors="clr-namespace:MyApplication.Desktop.Client.Behaviors" 
xmlns:core="using:Microsoft.Xaml.Interactions.Core" 
xmlns:command="http://www.galasoft.ch/mvvmlight" 

나는 또한 버튼으로 XAML 코드를 추가했습니다 :

<Button Grid.Column="2" 
    Command="{Binding SaveAttachmentCommand}" 
    Visibility="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled, Converter={StaticResource boolToVisibilityConverter}}" 
    Style="{StaticResource AttachmentSaveButtonStyle}"> 

    <i:Interaction.Triggers> 
    <i:EventTrigger EventName="PreviewMouseLeftButtonDown"> 
    <command:EventToCommand Command="{Binding LeftMouseButtonDownCommand}"/> 
    </i:EventTrigger> 
    </i:Interaction.Triggers> 

    <i:Interaction.Behaviors> 
    <behaviors:FrameworkElementDragBehavior> 
    </behaviors:FrameworkElementDragBehavior> 
    </i:Interaction.Behaviors> 
</Button> 

하지만 (FrameworkElementDragBehavior를 동작 클래스를 이야기하는 방법을 모른다) 처리 할 이벤트와 처리 방법 (호출 할 함수)을 지정합니다.

일부 자습서를 읽었지만 여전히 혼란 스럽습니다.

답변

0

두 달 전에 MVVM을 사용하여 드래그 앤 드롭을해야했습니다.

일부 연구 후 personnaly가이를 달성하는 가장 좋은 방법은 "GongSolutions DragDrop"라이브러리를 사용하는 것입니다. 매우 간단하며 원하는 것을 찾는데 이상적입니다. 트 리뷰에서 예를 들어 :

<TreeView ItemsSource="{Binding LstCat}" 
       dd:DragDrop.IsDragSource="True" 
       dd:DragDrop.IsDropTarget="True" 
       dd:DragDrop.DragAdornerTemplate="{StaticResource DragAdorner}"> 
    //Treeview Structure 

    </TreeView> 

거기에서 당신은 트 리뷰에서 드래그 & 드롭을 할 수 있습니다. dragAdorner도 추가 할 수 있습니다 (드래그 할 때 포인터 옆에있는 이미지)

viewModel에서 라이브러리와 함께 제공되는 인터페이스를 구현하여 드래그 또는 드롭의 동작을 알 수 있습니다. 이렇게하면 드래그하는 데이터에 액세스 할 수 있습니다. 예를 들어 : https://github.com/punker76/gong-wpf-dragdrop

: 여기

public void DragOver(IDropInfo dropInfo) 
    { 
     if (dropInfo.Data is Category && dropInfo.TargetItem is Rubrique) 
     { 
      return; 
     } 

     dropInfo.DropTargetAdorner = DropTargetAdorners.Highlight; 
     dropInfo.Effects = DragDropEffects.Move; 
    } 

당신이 관심이 있다면 라이브러리의 링크입니다