2012-11-25 21 views
5

मेरे पास आइटम (ऑब्जर्जेबल कोलेक्शन) के साथ मेनपेज व्यू मॉडेल है। इस पृष्ठ पर मेरे पास एक बटन भी है, जो आइटम में नए आइटम जोड़ता है।कैलिबर्न माइक्रो में टॉम्बस्टनिंग

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] का प्रयास करें।

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); 
     } 
    } 
    } 
} 

उत्तर

4
  1. आप नहीं InAppSettings लेकिन InPhoneState संग्रहीत करना चाहिए।
  2. विधि Configure कहा जाता है तो ब्रेकपॉइंट के साथ जांचें। यदि नहीं - आपके बूटस्ट्रैपर के साथ कुछ गलत है। शायद PhoneContainer.RegisterPhoneServices() गुम है
  3. विजुअल स्टूडियो (Ctrl + Alt + E, और सीएलआर अपवादों के खिलाफ चेकबॉक्स डालने) में पहला मौका अपवाद पकड़ना चालू करें। शायद आपका दृश्य मॉडल ठीक से deserialized नहीं किया जा सकता है।
संबंधित मुद्दे