0

I am creating a WPF and I have also created a side menu for different processes I want to perform. Currently all my code resides in the mainwindoe.xaml.cs. I would like to break out my into seperate files. For example menuitem1 code in one file, menuitem2 code in another file, etc. I prefer this method as I feel it is cleaner and easier to maintain. However I have tried doing Project-->Add Page-->Class but I don't know how to reference the code in the new page. Any help would be greatly appreciated.

Thank you, Kent

Cass
  • 537
  • 1
  • 7
  • 24
  • 2
    Without knowing the processes your want to perform, it becomes a question about the basics of coding. Dont know if this can be answered this easy. Maybe a suggestion for a good place to read about C# would be the better way: http://www.tutorialspoint.com/csharp/. According your question its the topic **encapsulation** http://www.tutorialspoint.com/csharp/csharp_encapsulation.htm. – C4d Jun 17 '16 at 12:21

2 Answers2

1

Well, in your class file you have the following:

namespace myNamespace
  {
      public class MyClass
        {
          public void MyMethod() { }
        }
  }

Let's assume that you have this in an assembly named MyDll.dll. You'd use it as follows:

  1. You add a reference to MyDll.dll within the solution explorer
  2. You include the namespace with using myNamespace;
  3. Then you can use your class doing MyClass test = new MyClass();

If you don't add the namespace like Number 2., you'd use your class like:

myNamespace.MyClass test = new myNamespace.MyClass();
0

You can to put all files in the same or a abstraced namespace. And You have to work with classes in c#.

For example

  • yourapp.mainwindoe
  • yourapp.menuitem1
  • yourapp.menuitem2

Addionally You have to set the classes You Need to Access from another Namespace to at least internal security Setting.

namespace yourapp.mainwindoe
{
    class YourClass
    {
        internal static YourMethod()
        {
           yourapp.menuitem1.YourOtherMethod();
        }
}

namespace yourapp.menuitem1 
{
    class YourClassOther
    {
        internal static YourOtherMethod()
        {
           // do something here...
        }
}
kami
  • 244
  • 1
  • 3
  • 16