how to disable WPF window. RRS feed

  • Question

  • I have two WPF window(.xaml) .
    If user login information is correct it should disable login window and open another window....

    How can I  achieve IT

    Friday, June 26, 2009 9:13 AM

All replies

  • In the code behind of the button click (from the Login) you can check the credentials and if the user passes it, you simple can navigate to your second window or attach it to the root.
    Friday, June 26, 2009 11:21 AM
  • do  you want to disable to login screen of hide, i would you a dialog screen and when the login/pass is correct close the dialog screen

    Sunday, June 28, 2009 9:27 AM
  • Hi,

    you can disable using the property   IsEnabled=false;

    if you do that then you will not have access to all the controls in that window, apart from that you will have access only to the standard minimize,maximize,resize buttons if available on top right corner of the title. which is non client area.

    Prasad -
    Microsoft MVP
    • Proposed as answer by prasad22 Wednesday, July 1, 2009 5:25 PM
    Wednesday, July 1, 2009 5:24 PM
  • Hi Harshil,

    according to my understanding of your query, here I would like to propose a solution:

    Suppose you have your login window as 'winLogin' and next window after successful login is say 'winNext'.

    Please note that, winLogin & winNext are window names like e.g. in XAML,

    <Window x:Class="YourProjectName.LoginWindow" Name="winLogin" ...../>

    When you find that login is successful, you will call next window as:

    winNext obj = new winNext(this)  // where 'this' is reference of current window which is 'winLogin'


    Now, in 'winNext' write following code:

        public partial class winNext: Window

    winLogin  objLogin = new  winLogin ();       // Create & Initialise an object of Login Window

    winNext(winLogin obj) //Remember we have passed reference of 'winLogin' as 'this' when calling winNext after successful login



       objLogin = obj;         // assign the passed object of Login window to local object of winLogin created above.


    private void Window_Loaded(object sender, RoutedEventArgs e) //Loading event of winNext

    objLogin.IsEnabled = false; // Disable the Login Window



    Hope this will help...


    Laxmikant Deshpande

    Monday, August 4, 2014 11:23 AM
  • I think im quiet late with my answer although I think that I can help some other people by posting a possible solution for the problem:

    (other solutions I found on the internet or in this thread dont work for me)

    So first I want to clarify how I understand the problem... So we want to deactivate a WPF window like calling MessageBox.Show() is doing. This can be achieved by calling the following code in the window which is supposed to be activated while the rest of the windows are deactivated:


    Calling these two methods first hides the window and then shows it as a dialog which is what we want to have.


    And now if we call the "Show" method instead of the "ShowDialog" Method the windows return to their original state.

    I hope this solution helps you in your project... Regards Fabian

    • Edited by Fabian T Monday, June 18, 2018 4:34 PM
    Monday, June 18, 2018 4:32 PM