0

わかりましたので、添付イベントをコントロールに追加しようとしています。現在、Caliburn は単純にこれをサポートしていませんが、回避策を提供していると思われる別の記事のコードを使用しました。基本的にこの種のコードを追加する方法が必要ですthis.AddHandler(RadDragAndDropManager.DragInfoEvent, new EventHandler<DragDropEventArgs>(OnDragInfo), true);が、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.

4

1 に答える 1

0

問題が見つかりました。エラーメッセージはこれについてあまり明白ではありません。ビューモデルのイベント ハンドラーは、xaml のターゲット メソッドの定義と一致する必要があります。この場合、xaml を次のように変更することで問題が修正されました。

                <cal:ActionMessage MethodName="OnDropQuery">
                    <cal:Parameter Value="$source" />
                    <cal:Parameter Value="$eventargs" />
                </cal:ActionMessage>

私も削除する必要がありましたcal:Action.TargetWithoutContext="{Binding Source={x:Static RelativeSource.Self}}"

于 2013-01-15T18:35:26.083 に答える