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 @@ + + +