-1

SQL Server に保存されたイベント名でイベントを発生させたい

SQL Server には ApplicationExitRequestEvent があります。メニュー ボタンをクリックすると、MenuItem から文字列が取得されます。

Type t = Type.GetType(SelectedMenu.View + "," + "AssemblyName");
var obj = Activator.CreateInstance(t);

if (t != null)
{
//Working firing Event with className
EventAggregator.GetEvent<ApplicationExitRequestEvent>().Publish(null);

//Generic?
EventAggregator.GetEvent<???>().Publish(null);
}

することは可能ですか?PRISM と MVVM の操作 - WPF - .NET 4.0

4

2 に答える 2

0

了解しました。現在は正常に動作しています。タイプ別にイベントを取得するために、Prism Library をポンピングしました :-)

    /// <summary>
    /// Gets the single instance of the event managed by this EventAggregator. 
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")]
    public CompositePresentationEvent<object> GetEvent(Type type)
    {
        EventBase existingEvent = null;
        events.TryGetValue(type, out existingEvent);

        if(existingEvent != null)
            return (CompositePresentationEvent<object>)existingEvent;

        return null;
    }

君たちありがとう!

于 2012-03-09T09:02:17.260 に答える
0

EventAggregator クラスを見ると、コンテナDictionary<Type, EventBase>GetEventメソッドにすぎないことがわかります。それだけです。実際の作業はすべて で行われEventBaseます。目的を達成するために、クラスを変更 (またはコピーを作成して変更) しGetEvent( string typeString )、typeString を実際の値に変換するメソッドを追加しType(コード サンプルと同じ方法)、それを使用してフェッチすることができます。辞書からのイベント。

于 2012-03-08T10:08:27.957 に答える