is it possible to make a button click event open a window? if so how should i do this? i mean a window that has already been created and marked up, im using wpf and am a staring programmer with not so very much knowledge of the language

5 Years
Discussion Span
Last Post by Mitja Bonca

1. You have a WPF project and It already has a window. You are able to run this application.

2. Now you right click on the project and Add new Window. You name it MyNewWindow.xaml

3. You would now notice MyNewWindow.xaml and MyNewWindow.xaml.cs added to your project. (the class name for the window would be MyNewWindow which is in the .xaml.cs file and it derives from Window; also a partial class)

4. Open the XAML file for the MyNewWindow (MyNewWindow.xaml) and add your controls. Treat it like any other window and write code.

5. Now in your main window (the first one) you add a Button which when clicked should show the newly created window.

For that inside the Click handler, ....

var newWindow = new MyNewWindow();

This would create a new instance of the MyNewWindow and shows it to the user. It would appear just as you designed in your XAML.

If this is an issue, let me know so that I will upload a sample application and link you with it.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.