Home > DeveloperSection > Forums > How get control from non-window class in WPF?
Brad Pitt
Brad Pitt

Total Post:61

Posted on    July-19-2013 2:53 AM


 1 Reply(s)
 1064  View(s)
Rate this:

Application.Current.MainWindow. ?

Vijay Shukla

Total Post:100

Posted on    July-19-2013 6:33 AM

If your control is in the main window of your application, you most likely need to cast it to the appropriate type. For example, if your "main window" is named Window1 (default naming), you could do:

Window1 myWindow = Application.Current.MainWindow as Window1;

if (myWindow != null)


     Button myButton = myWindow.button1; // Use your control here...

     myButton.IsEnabled = true; // Do something with the control here...


Don't want to miss updates? Please click the below button!

Follow MindStick