How get control from non-window class in WPF?

Total Post:61

Points:429

WPF 
WPF
 1558  View(s)
Ratings:
Rate this:

Application.Current.MainWindow. ?

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

      Modified On Mar-30-2018 05:31:33 AM

Answer

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.