我正在创建WPF,并且还为我要执行的不同过程创建了一个侧面菜单。目前,我所有的代码都位于mainwindoe.xaml.cs中。我想将我分解成单独的文件。例如,一个文件中的menuitem1代码,另一文件中的menuitem2代码,等等。我更喜欢这种方法,因为我觉得它更干净,更易于维护。但是我尝试做Project-> Add Page-> Class,但是我不知道如何在新页面中引用代码。任何帮助将不胜感激。
谢谢你,肯特
您可以将所有文件放在相同或抽象的名称空间中。并且您必须使用c#中的类。
例如
另外,您必须将需要从另一个命名空间访问的类至少设置为内部安全性设置。
namespace yourapp.mainwindoe
{
class YourClass
{
internal static YourMethod()
{
yourapp.menuitem1.YourOtherMethod();
}
}
namespace yourapp.menuitem1
{
class YourClassOther
{
internal static YourOtherMethod()
{
// do something here...
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句