protected override void OnNavigatedTo(NavigationEventArgs e) { if (PhoneApplicationService.Current.State.ContainsKey("AlarmViewModel")) { _alarmViewModel = (AlarmViewModel)PhoneApplicationService.Current.State["AlarmViewModel"]; foreach (AlarmItem alarm in App.ListAlarms) { _alarmViewModel.AddAlarm(alarm, listBoxAlarms); _listAlarms.Add(alarm); } if (_listAlarms.Count > 0) { listBoxAlarms.ItemsSource = _listAlarms; NoAlarmsTextBlock.Visibility = System.Windows.Visibility.Collapsed; } else { NoAlarmsTextBlock.Visibility = System.Windows.Visibility.Visible; } } else { // the view model could not be passed! fix it! Debug.Assert(true); } }
private void SetDataContext() { _alarmViewModel = new AlarmViewModel(); ContentPanel.DataContext = _alarmViewModel; }