Nicholas Mott
Nicholas Mott

Reputation: 112

How to show a grid based on previous window button click WPF c#

I have a button button UpdatePatient on the window MainMenuWindow. What I want the button to do is display the PatientMainWindow as well as the grid on the PatientMainWindow and change the label content to Update Patient.

private void button_updatePatient_Click(object sender, RoutedEventArgs e)
{
        gridHidden_True();
        PatientMainWindow patientMainWindow = new PatientMainWindow();
        patientMainWindow.ShowDialog();
        patientMainWindow.Grid_SelectPatient.Visibility = Visibility.Visible;
        patientMainWindow.label_PatientWindowType.Content = "Update Patient";
        this.Close();
}

gridHidden_True() is just a method that I have that hides grids on the current window.

When the new window displays the label content does not change and the grid is not set to visible.

Upvotes: 0

Views: 172

Answers (1)

Sinatr
Sinatr

Reputation: 22008

You are displaying modal window first and only then setting properties (after window is closed). You should set them first:

var patientMainWindow = new PatientMainWindow();
patientMainWindow.Grid_SelectPatient.Visibility = Visibility.Visible;
patientMainWindow.label_PatientWindowType.Content = "Update Patient";    
patientMainWindow.ShowDialog();

Upvotes: 1

Related Questions