I'm trying to build a small navigation system in my WPF application. I'm using this tutorial to navigate between pages. I want to add 'Go back' functionality on top of it for one UserControl
.
I have a UserControl Orders
and another UserControl Order
. Orders
is shown in MainWindow and when I click on an button, Order
UserControl
should be shown in the same place in MainWindow. I tried to put a reference to the Orders
usercontrol in the Order
usercontrol and navigate to the Orders
through Order
. But the Order
isn't destroyed since I'm using a variable from that class.
How can I make sure that when I navigate to Order
form Orders
, the Orders
isn't destroyed and when I navigate to Orders
from Order
, Order
is destroyed.
Button click event handler in Orders Class:
private void ShowOrder(object sender, RoutedEventArgs e)
{
Order order = new Order();
Switcher.Switch(order);
}
Return back button click handler in Order Class
public UserControl parent;
private void ReturnBack(object sender, RoutedEventArgs e)
{
Switcher.Switch(parent);
}