Commits

Christian Specht  committed 275a555 Draft

move INotifyPropertyChanged stuff to BaseViewModel

  • Participants
  • Parent commits 9a1ca22

Comments (0)

Files changed (4)

File src/MissileSharp.Launcher/MissileSharp.Launcher.csproj

       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </ApplicationDefinition>
+    <Compile Include="ViewModels\BaseViewModel.cs" />
     <Compile Include="ViewModels\MessageBoxWindowViewModel.cs" />
     <Compile Include="Views\MessageBoxWindow.xaml.cs">
       <DependentUpon>MessageBoxWindow.xaml</DependentUpon>

File src/MissileSharp.Launcher/ViewModels/BaseViewModel.cs

+using System.ComponentModel;
+
+namespace MissileSharp.Launcher.ViewModels
+{
+    /// <summary>
+    /// base class for all view models, implements INotifyPropertyChanged
+    /// </summary>
+    public class BaseViewModel : INotifyPropertyChanged
+    {
+        public event PropertyChangedEventHandler PropertyChanged;
+
+        protected void OnPropertyChanged(string name)
+        {
+            PropertyChangedEventHandler handler = PropertyChanged;
+            if (handler != null)
+            {
+                handler(this, new PropertyChangedEventArgs(name));
+            }
+        }
+    }
+}

File src/MissileSharp.Launcher/ViewModels/MainWindowViewModel.cs

 using System;
 using System.Collections.ObjectModel;
-using System.ComponentModel;
 using System.Linq;
 using System.Windows.Input;
 using MissileSharp.Launcher.Properties;
 
 namespace MissileSharp.Launcher.ViewModels
 {
-    public class MainWindowViewModel : INotifyPropertyChanged
+    public class MainWindowViewModel : BaseViewModel
     {
         private ICommandCenter model;
         private ICommandCenterService commandCenterService;
 
         public ICommand FireCommand { get; set; }
 
-        public event PropertyChangedEventHandler PropertyChanged;
-
         public MainWindowViewModel(ICommandCenterService commandCenterService, IConfigService configService, IMessageService messageService, IShutdownService shutdownService)
         {
             this.commandCenterService = commandCenterService;

File src/MissileSharp.Launcher/ViewModels/MessageBoxWindowViewModel.cs

-using System.ComponentModel;
-
+
 namespace MissileSharp.Launcher.ViewModels
 {
-    public class MessageBoxWindowViewModel : INotifyPropertyChanged
+    public class MessageBoxWindowViewModel : BaseViewModel
     {
-        public event PropertyChangedEventHandler PropertyChanged;
-
         private string messageText;
 
         public string MessageText
                 OnPropertyChanged("MessageText");
             }
         }
-
-        protected void OnPropertyChanged(string name)
-        {
-            PropertyChangedEventHandler handler = PropertyChanged;
-            if (handler != null)
-            {
-                handler(this, new PropertyChangedEventArgs(name));
-            }
-        }
     }
 }