When I click on a Button on my navigation bar, a new Window opens. For example:
private void btFinanzen_Click(object sender, RoutedEventArgs e)
{
Finanz mw = new Finanz(login);
mw.Show();
}
Now, I don´t want to show it in a new window. Instead of that, I want it to be shown at the same window. I tried with the following:
private void btFinanzen_Click(object sender, RoutedEventArgs e)
{
Finanz mw = new Finanz(login);
//mw.Show();
this.Content = Finanz f;
}
but it failed. What I should say is, that I´ve many of different windows now and want them all to be shown at one window - each by clicking a different button. How can I manage this?
What you have to do is to use a UserControl rather than a Window for your replaceable content. Add a new UserControl for each possible content you want to show in this.Content to your project. Add the content you had previously in the second window to the appropriate UserControl. After that you can simply instantiate the new control in your code and assign it to your content area of your main Window.
For example you create a UserControl ctlFinanz with the content of your previous Finanz window. Now you simply write:
this.Content = new ctlFinanz(login);
That's all :-)
I had the same problem and decided to create a seperate usercontrol for every window, put them in my wpf and set the visibility of all windows except the active one to Collapsed.
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