in Education by
I have a method in my Mainwindow, i want to call this method in an other usercontrol. I dont use a static method because my MainWindow is not Static, and I can't make it static. So I figured out to use this, but I dont know what comes behind the AS and I dont know if I can put a method is VAR? I also can't make another MainWindow instance because that gives me a Stackoverflow exception. How can I solve this? var myMethode= mainWindow.FindName("MyMethode") as (should be a methode); if (myMethode!= null) { //My code } JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You can define a static method on a class that is not static. For example: static void Main() { Foo foo = new Foo(); Foo.DoSomething(); foo.DoSomethingElse(); } public class Foo { public static void DoSomething() { Console.WriteLine("DoSomething"); } public void DoSomethingElse() { Console.WriteLine("DoSomethingElse"); } } But wouldn't it be a better solution to pass the MainWindow as a parameter into the User Control? So the user controls knows to which window it belongs and can access a function on it? (even better to declare an interface for this and pas the interface around). This would look like: public interface IWindow { string SomeWindowActivity(); } public class MyUserControl { public IWindow Window { get; set; } public void SomeActionOnUserControl() { string data = Window.SomeWindowActivity(); } } public class MainWindow : IWindow { MyUserControl MyUserControl { get; set; } public MainWindow() { // Link the UserControl to the Window it's one. This can be done trough the // constructor or a property MyUserControl.Window = this; } public string SomeWindowActivity() { // Some code... return "result"; } }

Related questions

0 votes
    I have a method in my Mainwindow, i want to call this method in an other usercontrol. I dont use ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    I have a method in my Mainwindow, i want to call this method in an other usercontrol. I dont use ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    What is the easiest way to call a web service from Excel (I am using version 2002)? Please, no ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    What is the easiest way to call a web service from Excel (I am using version 2002)? Please, no ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    A DoS attack coming from a large number of IP addresses, making it hard to manually filter or crash the ... -for-Cyber Security:,Cyber Security-Jobs:,Cyber Security Applications...
asked Oct 31, 2021 in Education by JackTerrance
0 votes
    When a user end a call from the CallKit UI the app ends the call and the actual VOIP call also ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 3, 2022 in Education by JackTerrance
0 votes
    How do I call Objective-C code from Swift?...
asked Mar 9, 2021 in Technology by JackTerrance
0 votes
    How can I remove this file from the repo without deleting my local copy of the file?...
asked Jan 8, 2021 in Technology by JackTerrance
0 votes
    Could someone tell me how to learn Cloud Computing with no IT background? Select the correct answer from above options...
asked Jan 6, 2022 in Education by JackTerrance
0 votes
    The basis of decision making depends upon the availability of ______and how we experience and understand it. ( ... /awareness.) Select the correct answer from above options...
asked Nov 12, 2021 in Education by JackTerrance
0 votes
    I am facing a problem that makes me to waste a lot of time. Each time I insert an element on a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
0 votes
    I am facing a problem that makes me to waste a lot of time. Each time I insert an element on a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 10, 2022 in Education by JackTerrance
0 votes
    How can I clone or deep copy an object so that the cloned object can be modified without any changes being reflected in the original object?...
asked Jan 15, 2021 in Technology by JackTerrance
0 votes
    I have an EC2 instance running (FreeBSD 9 AMI ami-8cce3fe5), and I can ssh into it using my amazon-created ... it can be prevented? Select the correct answer from above options...
asked Jan 31, 2022 in Education by JackTerrance
0 votes
    How can you call a controller method from JavaScript?...
asked Nov 11, 2020 in Technology by JackTerrance
...