From 02c3d7910f141119b3685a8b5dfc3d0beda3f0c4 Mon Sep 17 00:00:00 2001
From: chylex <chylex@fo2.cz>
Date: Fri, 3 Apr 2015 14:20:34 +0200
Subject: [PATCH] Added page frame and page manager

---
 BackupEssentials/AppPageManager.cs          | 25 +++++++++++++++++++++
 BackupEssentials/BackupEssentials.csproj    | 13 ++++++++---
 BackupEssentials/Controls/ButtonMainMenu.cs |  7 ++++++
 BackupEssentials/MainWindow.xaml            |  6 ++---
 BackupEssentials/MainWindow.xaml.cs         |  4 ++++
 5 files changed, 49 insertions(+), 6 deletions(-)
 create mode 100644 BackupEssentials/AppPageManager.cs

diff --git a/BackupEssentials/AppPageManager.cs b/BackupEssentials/AppPageManager.cs
new file mode 100644
index 0000000..fe7f2ac
--- /dev/null
+++ b/BackupEssentials/AppPageManager.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Windows.Controls;
+
+namespace BackupEssentials{
+    class AppPageManager{
+        private static Dictionary<Type,Page> cached = new Dictionary<Type,Page>();
+
+        public static T GetPage<T>() where T : Page, new(){
+            if (cached.ContainsKey(typeof(T)))return (T)cached[typeof(T)];
+
+            T page = new T();
+            cached[typeof(T)] = page;
+            return page;
+        }
+
+        public static Page GetPage(Type type){
+            if (cached.ContainsKey(type))return cached[type];
+
+            Page page = (Page)Activator.CreateInstance(type);
+            cached[type] = page;
+            return page;
+        }
+    }
+}
diff --git a/BackupEssentials/BackupEssentials.csproj b/BackupEssentials/BackupEssentials.csproj
index 1bf816a..47595ed 100644
--- a/BackupEssentials/BackupEssentials.csproj
+++ b/BackupEssentials/BackupEssentials.csproj
@@ -61,10 +61,19 @@
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </ApplicationDefinition>
+    <Compile Include="AppPageManager.cs" />
+    <Compile Include="Pages\About.xaml.cs">
+      <DependentUpon>About.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Controls\ButtonMainMenu.cs" />
     <Compile Include="TestingWindow.xaml.cs">
       <DependentUpon>TestingWindow.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Utils\WindowsVersion.cs" />
+    <Page Include="Pages\About.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="MainWindow.xaml">
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
@@ -111,9 +120,7 @@
     </None>
     <AppDesigner Include="Properties\" />
   </ItemGroup>
-  <ItemGroup>
-    <Folder Include="Fonts\" />
-  </ItemGroup>
+  <ItemGroup />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Import Project="$(MSBuildExtensionsPath)\Microsoft\Expression\Blend\.NETFramework\v4.5\Microsoft.Expression.Blend.WPF.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
diff --git a/BackupEssentials/Controls/ButtonMainMenu.cs b/BackupEssentials/Controls/ButtonMainMenu.cs
index 6125baf..65588cd 100644
--- a/BackupEssentials/Controls/ButtonMainMenu.cs
+++ b/BackupEssentials/Controls/ButtonMainMenu.cs
@@ -4,6 +4,13 @@ using System.Windows.Controls;
 
 namespace BackupEssentials.Controls{
     public class ButtonMainMenu:Button{
+        public static DependencyProperty ClickPageProperty = DependencyProperty.Register("ClickPage",typeof(string),typeof(ButtonMainMenu));
+
+        public string ClickPage {
+            get { return (string)base.GetValue(ClickPageProperty); }
+            set { base.SetValue(ClickPageProperty,(string)value); }
+        }
+
         private bool IsCheckedVar;
 
         public bool IsChecked {
diff --git a/BackupEssentials/MainWindow.xaml b/BackupEssentials/MainWindow.xaml
index fb5075d..03fce06 100644
--- a/BackupEssentials/MainWindow.xaml
+++ b/BackupEssentials/MainWindow.xaml
@@ -7,7 +7,7 @@
         xmlns:custom="clr-namespace:BackupEssentials.Controls"
         xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
         mc:Ignorable="d" x:Class="BackupEssentials.MainWindow"
-        Title="Backup" Height="600" Width="800" WindowStartupLocation="CenterScreen" WindowStyle="None" ResizeMode="CanResizeWithGrip" Background="#FF000000" AllowsTransparency="True" MinWidth="540" MinHeight="240">
+        Title="Backup" Height="600" Width="800" WindowStartupLocation="CenterScreen" WindowStyle="None" ResizeMode="CanResizeWithGrip" Background="#FF000000" AllowsTransparency="True" MinWidth="800" MinHeight="600">
     <Window.Resources>
         <sys:String x:Key="PathButtonClose">M7,0 L9,0 9,7 16,7 16,9 9,9 9,16 7,16 7,9 0,9 0,7 7,7 z</sys:String>
         <sys:String x:Key="PathButtonMaximized">M1,2 L1,9 13,9 13,2 z M0,0 L14,0 14,10 0,10 z</sys:String>
@@ -21,7 +21,6 @@
             <RowDefinition Height="60"/>
             <RowDefinition Height="2"/>
             <RowDefinition Height="*"/>
-            <RowDefinition Height="2"/>
             <RowDefinition Height="16"/>
 		</Grid.RowDefinitions>
 		<DockPanel x:Name="TitleBar" LastChildFill="False" VerticalAlignment="Top" Width="Auto" Height="36" MouseLeftButtonDown="TitleBarLeftButtonDown">
@@ -242,5 +241,6 @@
             <custom:ButtonMainMenu Content="Settings" Click="ButtonMainMenuClick" Grid.Column="6" Style="{DynamicResource ButtonStyleMainMenu}"/>
             <custom:ButtonMainMenu Content="About" Click="ButtonMainMenuClick" Grid.Column="8" Style="{DynamicResource ButtonStyleMainMenu}"/>
 		</Grid>
-	</Grid>
+        <Frame x:Name="ContentFrame" Content="" Margin="0" Grid.Row="4" NavigationUIVisibility="Hidden"/>
+    </Grid>
 </Window>
diff --git a/BackupEssentials/MainWindow.xaml.cs b/BackupEssentials/MainWindow.xaml.cs
index 83a39b8..1ec8e6e 100644
--- a/BackupEssentials/MainWindow.xaml.cs
+++ b/BackupEssentials/MainWindow.xaml.cs
@@ -1,5 +1,6 @@
 using BackupEssentials.Controls;
 using System;
+using System.Reflection;
 using System.Windows;
 using System.Windows.Forms;
 using System.Windows.Input;
@@ -67,6 +68,9 @@ namespace BackupEssentials{
             }
 
             btn.IsChecked = true;
+
+            Type pageType = GetType().Assembly.GetType("BackupEssentials."+btn.ClickPage,false);
+            ContentFrame.Navigate(pageType == null ? null : AppPageManager.GetPage(pageType));
         }
     }
 }