Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Loading New Windows

$
0
0

Using WPF and C# -

I am writing a program which has two windows - Window1 (login window) and Window2 (main part of the program).  When the program starts Window1 opens normally and prompts user for password.  When a valid password is entered Window1 closes and Window2 opens.  The code for this is:

var newW = new Window2();
this.Close();
newW.Show();
return;

During use of program from within Window2, administrative functions are required.  The program has an Admin button which has the following code:

adminval = 1;
var newW = new Window1();
newW.Show();
this.Close();
return;

Window1 opens normally and prompts for an Admin password.  When password is entered this code is executed:

if (Window2.adminval == 1)
{
  su = userid;
  var newW = new Window2();
  newW.Show();
  this.Close();
  return;
}

The bottom falls out at this point.  The program gets to Window2 but fails at InitializeComponent(); in this code -

public Window2()
{
   InitializeComponent();
...
}

The specific error message given is "NullReferenceException was unhandled. Object reference not set to an instance of an object."

What is causing this and how to I correct the issue?

Thank you in advance.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>