/// <summary> /// Restores the user selections. This can be used when we are navigating from /// the main page, or are returning from a tombstone operation. /// </summary> internal static void RestoreUserSelections() { CategoryPageState p = ApplicationState.CategoryPageInformation; // If we are on the favorite tab, we handle the data binding differently if (p.IsFavorite) { return; } // In case the user does not make any changes or selections, we need to have the data // to send back to the main page, so we select the current conversion units CategoryInformation c = ApplicationState.UnitCategoryAccess[p.Category]; try { if ((p.SourceUnitName != null) && (c.PivotUnitSelect.fromListView.ItemsSource != null)) { c.PivotUnitSelect.fromListView.SelectedItem = c.FindUnit(p.SourceUnitName); } else { c.PivotUnitSelect.fromListView.SelectedIndex = -1; } if ((p.TargetUnitName != null) && (c.PivotUnitSelect.toListView.ItemsSource != null)) { c.PivotUnitSelect.toListView.SelectedItem = c.FindUnit(p.TargetUnitName); } else { c.PivotUnitSelect.toListView.SelectedIndex = -1; } } catch (Exception e) { ApplicationState.ErrorLog.Add(new ErrorLog("RestoreUserSelections", e.Message)); c.PivotUnitSelect.fromListView.SelectedIndex = -1; c.PivotUnitSelect.toListView.SelectedIndex = -1; } }
/// <summary> /// Syncs the state of selections on this page to the main application state /// objetc. THis will be used for either Tombstone support, or returning to the main /// application page /// </summary> /// <param name="pivotIndex">Index of the page in the pivot control</param> internal void SyncStateToAppState(Int32 pivotIndex) { CategoryPageState c = ApplicationState.CategoryPageInformation; ApplicationState.CategoryPageInformation.PivotSelectedIndex = pivotIndex; // We may have an invalid unit category if we chose a favorite and then deleted // it, in which case the user has not made a selection. We will set the // apply flag to false so that the main page will not try to apply the settings // from this page. if (!String.IsNullOrEmpty(c.Category)) { // Favorite category is not in the list of supported categories, because // it is not in the XML file. if (ApplicationState.UnitCategoryAccess.ContainsKey(c.Category)) { // Non favorite category selection CategoryInformation category = ApplicationState.UnitCategoryAccess[c.Category]; // We only set the selection information back on the app for use on the main // page if it's valid. The user must have chosen an item for the to and from // unit list on the same category. // Our category is only updated once we've made a selection // in both the to/from list boxes in order // for the main page to update the conversion information if (!(category.IsUnit(c.SourceUnitName) && category.IsUnit(c.TargetUnitName))) { // The unit selections are not both valid. Don't apply any change c.Apply = false; } } else { // Favorite category case c.Apply = this.lastSelectedFavorite != null ? true : false; } } else { c.Apply = false; } }