【发布时间】:2017-06-23 09:34:39
【问题描述】:
我需要修改一个使用 WPF、MVVM 和行为进行事件处理的桌面应用程序。我的任务是为按钮实现拖放。如果用户按下按钮,它将弹出一个文件保存窗口,但如果用户单击并拖动它,它应该显示一个文件图标,并让用户将其拖放到资源管理器窗口中以将其保存在那里。
我已经添加了命名空间:
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)处理哪些事件以及如何处理它们(调用哪些函数)。
我已经阅读了一些教程,但我仍然感到困惑。
【问题讨论】:
标签: c# wpf mvvm desktop-application attachedbehaviors