[英]WPF - How to access method declared in App.xaml.cs?
如何使用 C# 访问 App.xaml.cs 中声明的公共实例方法?
((App)Application.Current).YourMethod ....
您是否考虑过创建一个单独的类来保存您的应用程序范围的方法(例如AppState.cs)?
You can also add a static property in your App
class with new
modifier like so:您还可以使用
new
修饰符在App
类中添加静态属性,如下所示:
public static new App Current => Application.Current as App;
This way you can access your method like so:这样你就可以像这样访问你的方法:
App.Current.YourMethod()
Check this answer about new modifier on SO.检查这个关于 SO 上的新修饰符的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.