diff --git a/ISwitchable.cs b/ISwitchable.cs
new file mode 100644
index 0000000..f3ae699
--- /dev/null
+++ b/ISwitchable.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PageSwitcher
+{
+ interface ISwitchable
+ {
+ void UtilizeState(object state);
+ }
+}
diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs
index 1a42ccc..c5eca90 100644
--- a/MainWindow.xaml.cs
+++ b/MainWindow.xaml.cs
@@ -23,6 +23,27 @@ namespace PageSwitcher
public MainWindow()
{
InitializeComponent();
+ Switcher.pageSwitcher = this;
+ Switcher.Switch(new UserControl1());
+ }
+
+ public void Navigate(UserControl nextPage)
+ {
+ this.Content = nextPage;
+ }
+
+ public void Navigate(UserControl nextPage, object state)
+ {
+ this.Content = nextPage;
+ ISwitchable s = nextPage as ISwitchable;
+
+ if (s != null)
+ {
+ s.UtilizeState(state);
+ } else
+ {
+ throw new ArgumentException("NextPage is not ISwichable! " + nextPage.Name.ToString());
+ }
}
}
}
diff --git a/PageSwitcher.csproj b/PageSwitcher.csproj
index c56c2ac..3e53999 100644
--- a/PageSwitcher.csproj
+++ b/PageSwitcher.csproj
@@ -55,6 +55,13 @@
MSBuild:Compile
Designer
+
+
+ UserControl1.xaml
+
+
+ UserControl2.xaml
+
MSBuild:Compile
Designer
@@ -63,10 +70,19 @@
App.xaml
Code
+
MainWindow.xaml
Code
+
+ Designer
+ MSBuild:Compile
+
+
+ Designer
+ MSBuild:Compile
+
diff --git a/Switcher.cs b/Switcher.cs
new file mode 100644
index 0000000..390de22
--- /dev/null
+++ b/Switcher.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Controls;
+
+namespace PageSwitcher
+{
+ public static class Switcher
+ {
+ public static MainWindow pageSwitcher;
+ public static void Switch(UserControl newPage)
+ {
+ pageSwitcher.Navigate(newPage);
+ }
+
+ public static void Switch(UserControl newPage, object state)
+ {
+ pageSwitcher.Navigate(newPage, state);
+ }
+ }
+}
diff --git a/UserControl1.xaml b/UserControl1.xaml
new file mode 100644
index 0000000..c3b45c7
--- /dev/null
+++ b/UserControl1.xaml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
diff --git a/UserControl1.xaml.cs b/UserControl1.xaml.cs
new file mode 100644
index 0000000..aa13fcf
--- /dev/null
+++ b/UserControl1.xaml.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace PageSwitcher
+{
+ ///
+ /// Interaction logic for UserControl1.xaml
+ ///
+ public partial class UserControl1 : UserControl
+ {
+ public UserControl1()
+ {
+ InitializeComponent();
+ }
+
+ private void button1_Click(object sender, RoutedEventArgs e)
+ {
+ Switcher.Switch(new UserControl2());
+ }
+ }
+}
diff --git a/UserControl2.xaml b/UserControl2.xaml
new file mode 100644
index 0000000..ddbb3f6
--- /dev/null
+++ b/UserControl2.xaml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
diff --git a/UserControl2.xaml.cs b/UserControl2.xaml.cs
new file mode 100644
index 0000000..c02f544
--- /dev/null
+++ b/UserControl2.xaml.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace PageSwitcher
+{
+ ///
+ /// Interaction logic for UserControl2.xaml
+ ///
+ public partial class UserControl2 : UserControl
+ {
+ public UserControl2()
+ {
+ InitializeComponent();
+ }
+
+ private void button_Click(object sender, RoutedEventArgs e)
+ {
+ Switcher.Switch(new UserControl1());
+ }
+ }
+}