protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); GameState game = SettingsProvider.LoadSavedGame(); if (game == null) { NavigationService.Navigate(new Uri("/Pages/NewGame.xaml", UriKind.Relative)); } else { //... } }
SuspensionManager
class, which implements the mechanism for saving sessions. Then in the page class you need to define the NavigationHelperLoadState
and NavigationHelperSaveState
methods. The NavigationHelperLoadState
code is shown below, state saving is similar. private async void NavigationHelperLoadState(object sender, LoadStateEventArgs e) { try { if (SuspensionManager.SessionState.ContainsKey("game-data")) { string previousGame = SuspensionManager.SessionState["game-data"] as string; if (!string.IsNullOrEmpty(previousGame)) { GameStateModel game = GameStateModel.FromJson(previousGame); if (game != null) { LoadGameToBoard(game.ToGameState()); } } } } catch (FileNotFoundException fileNotFound) { } catch (Exception) { } }
public static GameState LoadSavedGame() { try { IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings; if (settings.Contains(SavedGame)) { string previousGame = settings[SavedGame] as string; if (!string.IsNullOrEmpty(previousGame)) { GameStateModel game = GameStateModel.FromJson(previousGame); if (game != null) { return game.ToGameState(); } } } } catch (Exception exception) { } return null; }
<!-- Fonts --> <FontFamily x:Key="ThemeFontFamily">Segoe UI Light</FontFamily> <FontWeight x:Key="ThemeFontWeight">SemiLight</FontWeight>
/// <summary> /// Provides access to string resources. /// </summary> public class LocalizedStrings { private static AppResources _localizedResources = new AppResources(); public AppResources LocalizedResources { get { return _localizedResources; } } }
<Application.Resources> <winPhone8:LocalizedStrings xmlns:local="clr-namespace:Oxozle.Sudoku.WinPhone8" x:Key="LocalizedStrings"/> </Application.Resources>
<TextBlock Text="{Binding LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}" Style="{StaticResource PhoneTextNormalStyle}"/>
BuildLocalizedApplicationBar
method is BuildLocalizedApplicationBar
. But there is nothing difficult to write a few lines to build the application menu. private void BuildLocalizedApplicationBar() { // Set the page's ApplicationBar to a new instance of ApplicationBar. ApplicationBar = new ApplicationBar(); //// Create a new button and set the text value to the localized string from AppResources. //ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/edit.png", UriKind.Relative)); //appBarButton.Text = AppResources.GamePage_Pencil; //ApplicationBar.Buttons.Add(appBarButton); // Create a new menu item with the localized string from AppResources. ApplicationBarMenuItem appBarNewGame = new ApplicationBarMenuItem(AppResources.NewGameTitle); appBarNewGame.Click += delegate { NavigationService.Navigate(new Uri("/Pages/NewGame.xaml", UriKind.Relative)); }; ApplicationBar.MenuItems.Add(appBarNewGame); ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.GamePage_ButtonAbout); appBarMenuItem.Click += delegate { NavigationService.Navigate(new Uri("/Pages/AboutPage.xaml", UriKind.Relative)); }; ApplicationBar.MenuItems.Add(appBarMenuItem); ApplicationBarMenuItem appBarRate = new ApplicationBarMenuItem(AppResources.WinGame_Rate); appBarRate.Click += delegate { MarketplaceReviewTask marketplaceReviewTask = new MarketplaceReviewTask(); marketplaceReviewTask.Show(); }; ApplicationBar.MenuItems.Add(appBarRate); }
InitializeLanguage
method. // Language display initialization InitializeLanguage(); // ( ). private void InitializeLanguage() { try { // Set the font to match the display language defined by the // ResourceLanguage resource string for each supported language. // // Fall back to the font of the neutral language if the Display // language of the phone is not supported. // // If a compiler error is hit then ResourceLanguage is missing from // the resource file. RootFrame.Language = XmlLanguage.GetLanguage(AppResources.ResourceLanguage); // Set the FlowDirection of all elements under the root frame based // on the ResourceFlowDirection resource string for each // supported language. // // If a compiler error is hit then ResourceFlowDirection is missing from // the resource file. FlowDirection flow = (FlowDirection)Enum.Parse(typeof(FlowDirection), AppResources.ResourceFlowDirection); RootFrame.FlowDirection = flow; } catch { // If an exception is caught here it is most likely due to either // ResourceLangauge not being correctly set to a supported language // code or ResourceFlowDirection is set to a value other than LeftToRight // or RightToLeft. if (Debugger.IsAttached) { Debugger.Break(); } throw; } }
[assembly: NeutralResourcesLanguageAttribute("en-US")]
Source: https://habr.com/ru/post/206852/
All Articles