protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { this.SupportedOrientations = GamePage.get().SupportedOrientations; if (e.NavigationMode != System.Windows.Navigation.NavigationMode.Back) { base.OnNavigatedTo(e); this.viewModel = NavigationContext.GetData <SettingsPageViewModel>(); this.DataContext = this.viewModel; LanguageResources.Instance.UpdateControl(this); } }
public static void NOPH_SettingsDialog_showDialog(int all_settings_addr, int is_metric_system, int on_save_callback) { // Make sure the languages and prompts were loaded first languagesLoaded.WaitOne(); promptsLoaded.WaitOne(); // Read the settings SettingsPageViewModel viewModel = new SettingsPageViewModel(is_metric_system == 1); int currentPtr = all_settings_addr; for (int i = 0; i < (int)SettingsPageViewModel.Settings.SettingsMaxValue; i++) { if (i < (int)SettingsPageViewModel.Settings.SettingsMaxCValue) { bool isValid = CRunTime.memory[currentPtr / 4] == 1; currentPtr += sizeof(int); string value = CRunTime.charPtrToString(currentPtr); currentPtr += 40; viewModel.SetSettingsValue((SettingsPageViewModel.Settings)i, isValid, value); } // This is saved locally in isolated storage else if (i > (int)SettingsPageViewModel.Settings.SettingsMaxCValue) { string propertyName = ((SettingsPageViewModel.Settings)i).ToString().Split('_')[1]; if (IsolatedStorageSettings.ApplicationSettings.Contains(propertyName)) { string value = IsolatedStorageSettings.ApplicationSettings[propertyName].ToString(); viewModel.SetSettingsValue((SettingsPageViewModel.Settings)i, true, value); } else // If no settings exist assume null. { viewModel.SetSettingsValue((SettingsPageViewModel.Settings)i, true, null); } } } // Set the callback viewModel.OnSettingsSaved += (sender, args) => { // Save the settings currentPtr = all_settings_addr; for (int i = 0; i < (int)SettingsPageViewModel.Settings.SettingsMaxValue; i++) { if (i < (int)SettingsPageViewModel.Settings.SettingsMaxCValue) { currentPtr += sizeof(int); // Skip the is valid - we don't update this CRunTime.stringToCharPtr(viewModel.GetSettingsValue((SettingsPageViewModel.Settings)i), currentPtr); string value = CRunTime.charPtrToString(currentPtr); currentPtr += 40; // And call the callback System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => { UIWorker.addUIEvent(on_save_callback, 0, 0, 0, 0, true); }); } // This is saved locally in isolated storage else if (i > (int)SettingsPageViewModel.Settings.SettingsMaxCValue) { string propertyName = ((SettingsPageViewModel.Settings)i).ToString().Split('_')[1]; if (!IsolatedStorageSettings.ApplicationSettings.Contains(propertyName)) { IsolatedStorageSettings.ApplicationSettings.Add(propertyName, viewModel.GetSettingsValue((SettingsPageViewModel.Settings)i)); } else { IsolatedStorageSettings.ApplicationSettings[propertyName]=viewModel.GetSettingsValue((SettingsPageViewModel.Settings)i); } IsolatedStorageSettings.ApplicationSettings.Save(); } } // After settings saved we need to update the app with new behaivour: SetSupportedPageOrientation(); SetLiveTile(true); }; // And navigate to the dialog System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => { var currentPage = ((App)Application.Current).RootFrame.Content as PhoneApplicationPage; currentPage.NavigationService.Navigate<SettingsPivotPage>(viewModel); }); }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { this.SupportedOrientations = GamePage.get().SupportedOrientations; if (e.NavigationMode != System.Windows.Navigation.NavigationMode.Back) { base.OnNavigatedTo(e); this.viewModel = NavigationContext.GetData<SettingsPageViewModel>(); this.DataContext = this.viewModel; LanguageResources.Instance.UpdateControl(this); } }