-2

In WPF form application

Menu and MenuItems are located on Main Window form, by default i kept it disabled

then on tab open which is a login form

MainWindow and Login Tab are different form and Login form is opened in TabControl which is located in MainWindow

now i want that when i login from login form, on successful login Menu and MenuItems should be enabled.

screenshot for reference is attached enter image description here please share code for the same

Thanks in advance

1 Answers1

0

When you are creating your new Login Tab from the MainWindow you can pass the whole MainWindow control (this) as a parameter to the Login tab.

From there you will be able to make calls on item inside the MainWindow from your Login Tab.

tabPage1.Enabled = false; // this disables the controls on it
tabPage1.Visible = false; // this hides the controls on it.

In the code below is taken from two separate Windows, the first one is called MainWindow and it has a button which opens a new window which I've called Window1.

MainWindow Code:

private void ButtonNewPage_Click(object sender, RoutedEventArgs e)
    {
        Window1 newWindow = new Window1(this);
        this.Hide();
        newWindow.Show();
    }

Window1 code, notice in the Window1 Constructor it takes a parameter of type MainWindow:

public partial class Window1 : Window
{
    private MainWindow parent;

    public Window1(MainWindow parent)
    {
        InitializeComponent();
        this.parent = parent;
    }

    private void ButtonOldPage_Click(object sender, RoutedEventArgs e)
    {
        this.Hide();
        parent.Show();
    }
}

*Edited to show passing an old Window to a new Window

8WmK
  • 106
  • 1
  • 8
  • can you please share code to pass MainWindow Control as parameter in main window and tab page where to place i actually confused at this poing – KETAN CHAVDA May 12 '18 at 05:50
  • I've added an explanation of passing windows to my original post – 8WmK May 14 '18 at 08:15