/// <summary> /// Change the data context of an existing window to display the indicated unit. /// Update the graphs. /// </summary> /// <remarks> /// The command is rejected if there is a window which already displays the indicated unit. /// In that case, the other window is focused. /// </remarks> /// <param name="window">Window to change</param> /// <param name="unit">Unit to display on the window</param> private void ChangeWindowUnit( VehicleDataWindow window, IUnitViewModel unit) { // Focus on an existing window if one already exists. if (this.vcleWindows.Exists(vw => vw.DataContext == unit)) { VehicleDataWindow existingWindow = this.vcleWindows.Find( vw => vw.DataContext == unit); existingWindow.Show(); existingWindow.Activate(); return; } if (window == null) { Logger.Instance.WriteLog("SubClassViewModel: failed to change unit in a window, failed to find valid window"); return; } window.DataContext = unit; if (unit.JourneysList != null) { window.SetUpGraph(unit.JourneysList); } else { window.SetUpGraph(new List <IJourneyViewModel>()); } }
/// <summary> /// Set up and show a vehicle data window for a unit. /// </summary> /// <param name="unit">Unit to display</param> private void ShowVcleData(IUnitViewModel unit) { VehicleDataWindow window; if (this.vcleWindows.Exists(vw => vw.DataContext == unit)) { window = this.vcleWindows.Find(vw => vw.DataContext == unit); } else { window = new VehicleDataWindow { DataContext = unit }; if (unit.JourneysList != null) { window.SetUpGraph(unit.JourneysList); } else { window.SetUpGraph(new List <IJourneyViewModel>()); } window.Closed += this.VcleDataWindowClosed; this.vcleWindows.Add(window); } window.Show(); window.Activate(); }
/// <summary> /// Display the previous unit. /// </summary> /// <param name="unit">Unit to display</param> private void PreviousUnit(IUnitViewModel unit) { int?index = this.GetUnitIndex(unit); if (index != null && index > 0) { VehicleDataWindow window = this.vcleWindows.Find(vw => vw.DataContext == unit); this.ChangeWindowUnit( window, this.Units[(int)index - 1]); } }