I want to create 2 separate windows in xaml and I want to control them separately from the code part. Do you have any idea how to do that ? If you can provide some code examples, I will be appreciated.
Thank you from now...
NavigationService is for browser navigation within WPF. What you are trying to do is change to a different window TrainingFrm . To go to a different window, you should do this: private void conditioningBtn_Click(object sender, RoutedEventArgs e) { var newForm = new TrainingFrm(); //create your new form.
WPF is still one of the most used app frameworks in use on Windows (right behind WinForms).
Add a second Window
(the first one being MainWindow.xaml) in your project (right click your project-> Add -> Window). Let's call it BobbyWindow.
In the constructor of MainWindow.xaml.cs, call:
BobbyWindow bWin = new BobbyWindow();
bwin.Owner = this;
bWin.Show();
voila.
EDIT: additional info to reflect the comments
The main difference between this:
public MainWindow()
{
InitializeComponent();
Window1 bWin = new Window1();
bWin.Owner = this;
bWin.Show();
}
And that:
Window1 bWin = new Window1();
public MainWindow()
{
InitializeComponent();
bWin.Owner = this;
bWin.Show();
}
Is that in the first case, bWin is local to the MainWindow() constructor, which means it only exists within the brackets of MainWindow().
In the second case, bWin is local to the class, which means it is only accessible from within the boundaries of the MainWindow class
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With