我有MainPageViewModel with Items(ObservableCollection)。在这个页面上,我还有一个按钮,可以向项目中添加新项目。
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;
}
}
}
添加新项目非常有效。
但是,当应用程序在逻辑删除后激活时,来自项目的数据无法恢复。尝试为我的ViewModel创建StorageHandler。没有帮助。我做错了什么?
public class MainPageViewModelStorage : StorageHandler<MainPageViewModel> {
public override void Configure() {
Property(x => x.Items)
.InAppSettings()
.RestoreAfterActivation();
}
}
另外尝试为类和属性添加[SurviveTombstone],但Visual Studio不知道该属性。
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);
}
}
}
}
答案 0 :(得分:4)
InAppSettings
而是InPhoneState
。 Configure
,请使用断点检查。如果不是 - 你的引导程序有问题。可能PhoneContainer.RegisterPhoneServices()
缺少