1

我试图将一个对象(它是一个类)保存到 OnNavigateFrom 事件处理程序内的页面状态字典中。每当应用程序被墓碑化时,我都会收到异常“System.Windows.ApplicationUnhandledExceptionEventArgs”。在 OnNavigateFrom 事件处理程序中是:

protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
     if (e.NavigationMode != System.Windows.Navigation.NavigationMode.Back)
     {
         try
         {
              if (Utility.TOMBED_CELEB.Length > 0) State["selectedCeleb"] = Utility.SelectedCeleb; //app not tombstoned, save celeb object
              else { System.Diagnostics.Debug.WriteLine("Could not find value for Celeb"); }
         }
         catch (Exception ex)
         {
             System.Diagnostics.Debug.WriteLine(ex.StackTrace);
         }                
     }
}

如果我注释掉该行

State["selectedCeleb"] = Utility.SelectedCeleb; //app not tombstoned, save celeb object

该应用程序不会抛出任何异常,当然在保存字符串对象时不会发生这种情况。如何将类保存到状态字典。下面是名人班

class Celebs : INotifyPropertyChanged
    {
        private BitmapImage _image;
        private String ImageString;

        public String Image
        {
            get
            {
                return ImageString;
            }
            set
            {
                this.ImageString = value;
                NotifyPropertyChange("Image");
            }
        }
        public BitmapImage ImageBitmap
        {
            get
            {
                return _image;
            }
            set
            {
                this._image = value;
                NotifyPropertyChange("ImageBitmap");
            }
        }
        public String Name{get;set;}
        public String Dob { get; set; }
        public String Country { get; set; }
        public String Aid { get; set; }
        public String Biography { get; set; }
        public String Twitter { get; set; }
        public String Facebook { get; set; }
        public String Google { get; set; }
        public String Website { get; set; }
        public String Youtube { get; set; }
        public JArray MovieActedIn { get; set; }
        public String Name_ { get; set; }
        public String Title { get; set; } //for search sake
        public String StarringActors { get; set; } //for search sake




        public void NotifyPropertyChange(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }     

        public event PropertyChangedEventHandler PropertyChanged;
    }
4

0 回答 0