2012-11-25 9 views
5

Mam MainPageViewModel z przedmiotami (ObservableCollection). Na tej stronie mam również przycisk, który dodaje nowe przedmioty do Przedmiotów.Tombstoning w Caliburn Micro

public class MainPageViewModel : Screen { 
    private DateTime StartActivity = DateTime.MinValue; 

    public ObservableCollection<ActivityViewModel> Items { get; set; } 

    public MainPageViewModel(INavigationService navigationService) { 
    this.Items = new ObservableCollection<ActivityViewModel>(); 
    } 

    public void AddActivity(string activityName) { 
    if (this.Items.Count == 0) { 
     this.Items.Add(new ActivityViewModel() { 
     Activity = activityName, 
     Duration = 0 
     }); 

     StartActivity = DateTime.Now; 
     } 
    else { 
     this.Items[this.Items.Count - 1].Duration = 10; 
     this.Items.Add(new ActivityViewModel() { 
     Activity = activityName, 
     Duration = 0 
     }); 

     StartActivity = DateTime.Now; 
    } 
    } 
} 

Dodawanie nowych elementów działa idealnie.

Jednak dane z elementów nie są odzyskiwane po aktywacji aplikacji po zakończeniu tombowania. Spróbuj utworzyć StorageHandler dla mojego ViewModel. Nie pomaga. Co robię źle?

public class MainPageViewModelStorage : StorageHandler<MainPageViewModel> { 
    public override void Configure() { 
    Property(x => x.Items) 
     .InAppSettings() 
     .RestoreAfterActivation(); 
    } 
} 

spróbować również dodać [SurviveTombstone] dla klasy i własności, ale Visual Studio nie wiedzą, że atrybut.

public class ActivityViewModel : PropertyChangedBase { 
    private string _activity; 
    public string Activity { 
    get { 
     return _activity; 
    } 
    set { 
     if (value != _activity) { 
     _activity = value; 
     NotifyOfPropertyChange(() => Activity); 
     } 
    } 
    } 

    private double _duration; 
    public double Duration { 
    get { 
     return _duration; 
    } 
    set { 
     if (value != _duration) { 
     _duration = value; 
     NotifyOfPropertyChange(() => Duration); 
     } 
    } 
    } 
} 

Odpowiedz

4
  1. należy przechowywać nie InAppSettings ale InPhoneState.
  2. Sprawdź z przerwaniem, jeśli wywoływana jest metoda Configure. Jeśli nie - coś nie tak z twoim bootstrapperem. Prawdopodobnie brak jest PhoneContainer.RegisterPhoneServices()
  3. Włącz wyjątek dotyczący przechwytywania pierwszej szansy w programie Visual Studio (Ctrl + Alt + E, a także pole wyboru przeciwko wyjątkom CLR). Prawdopodobnie twój model widoku nie może być poprawnie przekształcony w deserializację.
Powiązane problemy