我有一个类库,我们称之为Restarter
。现在我想从WPF应用程序调用方法Restart()
。
这里有一些代码放在Restarter
中以便更好地理解
public void Restart()
{
System.Windows.Application app = GetApplicationFromCaller();
...
}
我的WPF应用程序中的代码
public void Foo()
{
var restarter = new Restarter();
restarter.Restart();
}
是否可以从调用方法Application
获取Foo
?
我想如果有的话,只能通过反思。
答案 0 :(得分:2)
Application.Current
会为您提供最新的申请。但是,理想情况下,当您设计类库时,必须知道您是从WPF应用程序还是从任何其他类型的应用程序调用它。