public void Model_PropertyChanged(object sender, PropertyChangedEventArgs e) { MainWinMod m = sender as MainWinMod; if (m != null && m == model) { if (e.PropertyName.Equals("Lat")) { Lat = model.Lat; } if (e.PropertyName.Equals("Lon")) { Lon = model.Lon; } } }
//CTOR public MainWindow() { InitializeComponent(); IMainWinModel m = new MainWinMod(AutoPilotBox); vm = new ManuelPilotViewModel(m, joystick); FlightBoardViewModel fvm = new FlightBoardViewModel(m); AutoPilotViewModel avm = new AutoPilotViewModel(m); osvm = new OtherStuffViewModel(m); flightBoard.VM = fvm; m.PropertyChanged += fvm.Model_PropertyChanged; joystick.Moved += vm.JoyStick_Handler; this.DataContext = vm; autoPilotButt.DataContext = avm; clearButt.DataContext = avm; connectButt.DataContext = osvm; settButt.DataContext = osvm; Application.Current.MainWindow.Closing += new System.ComponentModel.CancelEventHandler(MainWindow_Closing); }