// The following section of code is used for generation of the Control UI as different aircraft have // different numbers of seats in a differnt layout this will provide that flexiblity #region UI_Generation /// <summary> /// Generates the view /// </summary> /// <returns></returns> private OperationResult GenerateView() { OperationResult operationResult = new OperationResult(); try { if (DataContext == null) { operationResult.Result = OperationResultValue.Failure; operationResult.Messages.Add("Empty Seating Grid View Model."); return(operationResult); } // Cast Datacontext to Seating Grid View Model SeatingGridViewModel = (DataContext as MainWindowViewModel).SeatingGridViewModel; // Set Aircraft title AircraftTitle.Text = $"{SeatingGridViewModel.Aircraft.Flight_Number}, {SeatingGridViewModel.Aircraft.Aircraft_Type}"; // Generate Seating Grid GenerateColumns(SeatingGridViewModel.Aircraft.Columns, SeatingGridViewModel.Aircraft.Aisles); GenerateAisles(SeatingGridViewModel.Aircraft.Columns, SeatingGridViewModel.Aircraft.Aisles); GenerateSeats(SeatingGridViewModel.Aircraft.Columns, SeatingGridViewModel.Aircraft.Aisles, SeatingGridViewModel.Aircraft.Seats); operationResult.Result = OperationResultValue.Success; } catch (Exception ex) { ex.Log(); } return(operationResult); }
/// <summary> /// EventHandler for when the datacontext changes to a different aircraft /// there may be a way to remove this now /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { try { // Cast Datacontext to Seating Grid View Model SeatingGridViewModel = (DataContext as MainWindowViewModel).SeatingGridViewModel; SeatingGridViewModel.PropertyChanged += UpdateView; } catch (Exception ex) { ex.Log(); } }