popup another form?

avmvldr

New member
Joined
Aug 3, 2023
Messages
2
Programming Experience
10+
I am pretty new to C# even though I've been developing software for quite some time. I also took about 4.5 years off from IT. Anyway, I'm trying to find a good FREE resource for learning this language. Right now, I'm trying to build a simple little WPF form with input and storing the data to a SQL Server DB.

My problem is, when I click a button, I just want to popup another form. I'm trying to use the following statement:

Form f = new Form();

Below is the code that I have right now.

C#:
using System.Windows;

namespace WpfApp1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void AddRecord_Click(object sender, RoutedEventArgs e)
        {
            ///How do I popup a form here
        }
    }
}


Thanks!
 
WPF uses classes that derive from Window. Windows Forms (aka WinForms) uses classes that derive from Form. I think you are trying to mix WPF and WinForms.

As an aside, you should first focus on learning how to use C# with just plain old console programs. Once you know the language pretty well then start learning the UI framework of your choice. Better to climb on learning curve at a time instead of trying to climb 2-3 learning curves simultaneously.

Anyway, you would do something like:
C#:
OtherWindow other = new OtherWindow();
other.Show();
which is similar to WinForms. You don't just all the constructor. You also need to tell it to show itself.
 
WPF uses classes that derive from Window. Windows Forms (aka WinForms) uses classes that derive from Form. I think you are trying to mix WPF and WinForms.

As an aside, you should first focus on learning how to use C# with just plain old console programs. Once you know the language pretty well then start learning the UI framework of your choice. Better to climb on learning curve at a time instead of trying to climb 2-3 learning curves simultaneously.

Anyway, you would do something like:
C#:
OtherWindow other = new OtherWindow();
other.Show();
which is similar to WinForms. You don't just all the constructor. You also need to tell it to show itself.

SkyDiver,

Thanks for your reply. I ended up figuring it out which is basically what you did. I'm also doing the C# tutorials on the Microsoft Docs site using the browser as a console...thanks again!
 
And maybe don't make WPF or WinForms the next thing you learn; they're not so in-demand these days
 

Latest posts

Back
Top Bottom