我有一个使用Caliburn Micro框架为MVVM编写的WPF应用程序。
我找到了从usercontrol的codebehind文件接受拖动文件到wpf应用程序的示例。我还没有找到一个如何使用MVVM方法正确执行此操作的示例?
有关如何执行此操作的任何提示?
答案 0 :(得分:0)
我在一起解决了一些问题,解决了我现在和现在的需求。可能更一般。
<i:Interaction.Triggers>
<Trigger:RoutedEventTrigger EventName="DragQuery">
<cal:ActionMessage MethodName="DragQuery">
<cal:Parameter Value="$source" />
<cal:Parameter Value="$eventArgs" />
<cal:Parameter Value="$view" />
</cal:ActionMessage>
</Trigger:RoutedEventTrigger>
<Trigger:RoutedEventTrigger EventName="DropQuery">
<cal:ActionMessage MethodName="DropQuery">
<cal:Parameter Value="$source" />
<cal:Parameter Value="$eventArgs" />
<cal:Parameter Value="$view" />
</cal:ActionMessage>
</Trigger:RoutedEventTrigger>
</i:Interaction.Triggers>
public class RoutedEventTrigger : EventTriggerBase<DependencyObject>
{
RoutedEvent _routedEvent;
public RoutedEvent RoutedEvent
{
get { return _routedEvent; }
set { _routedEvent = value; }
}
public string EventName { get; set; }
public RoutedEventTrigger() { }
protected override void OnAttached()
{
switch (EventName)
{
case "DragQuery":
RoutedEvent = UIElement.DragEnterEvent;
break;
case "DropQuery":
RoutedEvent = UIElement.DropEvent;
break;
default:
break;
}
Behavior behavior = base.AssociatedObject as Behavior;
FrameworkElement associatedElement = base.AssociatedObject as FrameworkElement;
if (behavior != null)
{
associatedElement = ((IAttachedObject)behavior).AssociatedObject as FrameworkElement;
}
if (associatedElement == null)
{
throw new ArgumentException("Routed Event trigger can only be associated to framework elements");
}
if (RoutedEvent != null)
{ associatedElement.AddHandler(RoutedEvent, new RoutedEventHandler(this.OnRoutedEvent)); }
}
void OnRoutedEvent(object sender, RoutedEventArgs args)
{
base.OnEvent(args);
}
protected override string GetEventName() { return RoutedEvent.Name; }
}