好吧,所以我試圖將附加事件添加到控件。現在Caliburn不支持這個天真,但我似乎提供了一種解決方法used code from a different article。我基本上需要一種方法來添加這種代碼this.AddHandler(RadDragAndDropManager.DragInfoEvent, new EventHandler<DragDropEventArgs>(OnDragInfo), true);
,但caliburn不支持附加事件。這裏是我的代碼:Caliburn與附加事件,目標失敗
<telerik:RadTreeView Height="250" Name="Root" Width="300" ItemTemplate="{StaticResource BusinessEntityTemplate}" IsDragDropEnabled="true" cal:Action.TargetWithoutContext="{Binding Source={x:Static RelativeSource.Self}}">
<i:Interaction.Triggers>
<Helpers:RoutedEventTrigger RoutedEvent="{x:Static dragDrop:RadDragAndDropManager.DropQueryEvent}" IncludeHandledEvents="True">
<cal:ActionMessage MethodName="OnDropQuery">
<!--<cal:Parameter Value="$eventargs" />-->
</cal:ActionMessage>
</Helpers:RoutedEventTrigger>
</i:Interaction.Triggers>
</telerik:RadTreeViewItem>-->
</telerik:RadTreeView>
RoutedEventTrigger定義如下:
public class RoutedEventTrigger : EventTriggerBase<DependencyObject>
{
RoutedEvent _routedEvent;
public RoutedEvent RoutedEvent
{
get { return _routedEvent; }
set { _routedEvent = value; }
}
bool _includeHandledEvents = false;
public bool IncludeHandledEvents
{
get { return _includeHandledEvents; }
set { _includeHandledEvents = value; }
}
public RoutedEventTrigger() { }
protected override void OnAttached()
{
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)); }
{ associatedElement.AddHandler(RoutedEvent, new RoutedEventHandler(this.OnRoutedEvent), this.IncludeHandledEvents); }
}
void OnRoutedEvent(object sender, RoutedEventArgs args)
{
base.OnEvent(args);
}
protected override string GetEventName() { return RoutedEvent.Name; }
}
,並在我的ViewModel我只是有一個這樣的處理程序:
public void OnDropQuery(object sender, DragDropQueryEventArgs e) {}
當我運行這個錯誤我得到是關於base.OnEvent(args);
約No target found for method OnDropQuery.
我很努力弄清楚爲什麼這不起作用。