Click here to Skip to main content
15,886,676 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I can't figure out how to invoke a method that I described in a WPF page that is located in a frame inside my mainwindow through my second WPF window.

I tried:(In the window that is invoking the method)

C#
var page= new Page1() as Page1; 
page.addgoal(txtbox_Name.Text);


(addgoal is my method)
I tried to invoke the method addgoal() though the method does not produce the desired result on Page1, which has to be open
Thanks to all!
Posted
Updated 28-Feb-15 15:06pm
v2
Comments
Sergey Alexandrovich Kryukov 28-Feb-15 20:58pm    
You don't "invoke" methods, you just call them. (But you invoke, say, delegate and event instances, delegate instances via the Dispatcher or directly.)
Calling a method is the most basic, fundamental and trivial thing. Therefore, it's hard to understand how it possibly could cause any confusions. Perhaps you can get help if you explain more.
—SA
Kevin Tabatabaei 28-Feb-15 21:05pm    
Alright, I want to call the method. Thank you for correcting my error for I am new to programming. In the window, I cannot simply write Page1.addgoal(string Name). And I also do not want to create a new instance of page 1 to open, so how can I call the method in my page?
Sergey Alexandrovich Kryukov 28-Feb-15 21:15pm    
Why cannot you? Actually, I don't know what is Page1. First of all, you need to understand static vs instance methods. Instance method is called on an instance (which is, technically, passed just the first implicit argument "this"), and static method is just the class/struct method. Understanding all that, you just apply some logic. But it you face the problem of how to design the code, I'll try to help.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900