Reputation: 448
I'm new to C# and I am trying to learn! But I've been stuck trying to get a new window to open! I've read various other similar questions here on StackOverflow and googled but found nothing!
I have two windows. One called MainWindow
and another called ChildForm
. I use the follow code on a button I named openNewForm
.
private void openNewForm_Click(object sender, EventArgs e)
{
ChildForm f2 = new ChildForm();
this.Hide();
f2.ShowDialog();
}
From my understanding, this is the standard way of opening a new window or form. I have seen some tutorials use var f2 = new ChildForm();
however. When trying to run my application, I get the following error message.
Severity Code Description Project File Line Error CS0246 The type or namespace name 'ChildForm' could not be found (are you missing a using directive or an assembly reference?) WpfApplication1 ... 38
I think this could possibly be a reference issue, but I am not entirely sure. Thanks in advance!
Upvotes: 1
Views: 570
Reputation: 968
Consider creating a window for your dialog and using it like this.
public class DialogWindow : Window
{
// Your custom dialog window.
}
Call it like so:
DialogWindow w = new DialogWindow();
if(w.ShowDialog() != false)
{
// Do stuff here
}
Upvotes: 2