我需要修改一個使用WPF,MVVM和Behaviors進行事件處理的桌面應用程序。我有一個任務來實現拖動&刪除按鈕。如果用戶按下按鈕,它將彈出一個文件保存窗口,但如果用戶單擊並拖動它,它應該顯示一個文件圖標,並讓用戶將其放入資源管理器窗口並將其保存在那裏。拖放行爲
我已經添加命名空間:
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 )處理哪些事件以及如何處理它們(調用哪些函數)。
我讀過一些教程,但我仍然感到困惑。