HOW GET CONTROL FROM NON-WINDOW CLASS IN WPF?

Brad Pitt

Total Post:61

Points:429
Posted by  Brad Pitt
WPF 
WPF
 1089  View(s)
Ratings:
Rate this:

Application.Current.MainWindow. ?

  1. Vijay Shukla

    Post:100

    Points:700
    Re: How get control from non-window class in WPF?

    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...

    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!