简体   繁体   中英

How to call a method used in another WPF window in c#?

I am creating a game like system which contains a trainingSession window and a testSession window. In the trainingSession window i have created a method - public void stage() which contain the neccesary data to run the session. Now i want this exact same method used in the testSession window. But how can i call it? I do not want to copy and paste the entie method again.

Is there a way i can do this? Thanks, e.mack

or is it possible to have this method in its own class file, which then can be called by both the trainingSession class and the testSession class... but then there would be alot of parameters needing to be passed over.

That's what inheritance is for!

Create a mustinherit class called baseSession. That's where method stage() goes.

Now, say that trainingSession and testSession both derive from baseSession. Voilà! -- stage() is now part of both testSession and trainingSession.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM