protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); RewardModel vm = ((App)(Application.Current)).ViewModel as RewardModel; this.DataContext = vm; //Work around Silverlight Toolkit Bug for ToggleSwitch this.RoomForMediaSwitch.IsChecked = vm.MakeRoomforMedia; }
private void ApplicationBarOKIconButton_Click(object sender, EventArgs e) { RewardModel vm = ((App)(Application.Current)).ViewModel as RewardModel; //Work around Silverlight Toolkit Bug for ToggleSwitch vm.MakeRoomforMedia = this.RoomForMediaSwitch.IsChecked.HasValue ? (bool)this.RoomForMediaSwitch.IsChecked : false; ((App)(Application.Current)).SaveData(); if (NavigationService.CanGoBack) { NavigationService.GoBack(); } }
public void LoadData() { // load the view model from isolated storage using (var store = IsolatedStorageFile.GetUserStoreForApplication()) using (var stream = new IsolatedStorageFileStream("data.txt", FileMode.OpenOrCreate, FileAccess.Read, store)) using (var reader = new StreamReader(stream)) { if (!reader.EndOfStream) { var serializer = new XmlSerializer(typeof(RewardModel)); ViewModel = (RewardModel)serializer.Deserialize(reader); } } }
// Code to execute when the application is launching (eg, from Start) // This code will not execute when the application is reactivated private void Application_Launching(object sender, LaunchingEventArgs e) { LoadData(); // if the view model is not loaded, create a new one if (ViewModel == null) { ViewModel = new RewardModel(); ViewModel.Update(); } // set the frame DataContext RootFrame.DataContext = ViewModel; }