Commits

Mark Heath committed 19674ba

Adding Module2, refactored MainWindow.xaml.cs to allow switching between modules as the selected index is changed

  • Participants
  • Parent commits c3d316b

Comments (0)

Files changed (2)

MainWindow.xaml.cs

         {
             InitializeComponent();
             this.listBox.Items.Add("Module 1");
-            this.contentPresenter.Content = new Module1();
+            this.listBox.Items.Add("Module 2");
+            this.listBox.SelectionChanged += (sender, args) => LoadModule(this.listBox.SelectedIndex);
+            this.listBox.SelectedIndex = 0;
+        }
+
+        private void LoadModule(int moduleIndex)
+        {
+            this.contentPresenter.Content = GetModuleContent(moduleIndex);
+        }
+
+        private UserControl GetModuleContent(int moduleIndex)
+        {
+            if (moduleIndex == 0) return new Module1();
+            return new Module2();
         }
     }
 }

ModularWPFTest.csproj

       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="Module2.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Module1.xaml.cs">
       <DependentUpon>Module1.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Module2.xaml.cs">
+      <DependentUpon>Module2.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Properties\AssemblyInfo.cs">
       <SubType>Code</SubType>
     </Compile>