Within my application, i use the hidden and visible porperties to make windows how or not show to the user.
Now at some point, when i am in Window1, i want to make a check if there is still a instance of the main window, that is hidden.
Googling, i found (also on SO) that i need to use this code:
Window deze = Application.Current.Windows.OfType<MainWindow>().Where(x => x.Name == "MainWindow").FirstOrDefault();
But whatever i fill in for the part OfType<MainWindow> or for the "MainWindow" it keeps returning null, even when im 100% sure there must be 1 instance.
Checking in the code of the main window, that is called in the solution explorer (visual express) “mainWindow.xaml”
i see that the code looks like this:
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
//creating the exitmessage for use later on, after all, we want to use this in an other method.
public MainWindow()
{
......
}
I really have no clue at all, why that “Window deze” keeps returning null when im 100% sure there is a hidden instance of the main window.
Anyone got an idea on this one ?
Im i just totally overlooking some logical solution ?
thanx in advance!
The
Whereis redundant, as you see it checks for a specific name, which does not concern you.