如何从另一个类库中获取WPF Application对象?

时间:2013-09-25 16:39:47

标签: reflection

我有一个类库,我们称之为Restarter。现在我想从WPF应用程序调用方法Restart()

这里有一些代码放在Restarter中以便更好地理解

    public void Restart()
    {
        System.Windows.Application app = GetApplicationFromCaller();
        ...
    }

我的WPF应用程序中的代码

    public void Foo()
    {
        var restarter = new Restarter();
        restarter.Restart();
    }

是否可以从调用方法Application获取Foo?  我想如果有的话,只能通过反思。

1 个答案:

答案 0 :(得分:2)

Application.Current会为您提供最新的申请。但是,理想情况下,当您设计类库时,必须知道您是从WPF应用程序还是从任何其他类型的应用程序调用它。