类型' System.Reflection.TargetInvocationException'的例外情况发生在System.Windows.ni.dll Windows Phone 8中

时间:2015-09-01 07:40:46

标签: c# windows-phone-8

我正在建立一个笔记应用程序。在笔记编辑页面上,当用户在文本中创建新笔记和类型,然后按手机的后退按钮时,代码假设创建一个新笔记,我尝试用新行替换回车。当我在应用程序中尝试这个时,我得到了这个异常。一个未处理的类型' System.Reflection.TargetInvocationException'发生在System.Windows.ni.dll中,并打开一个新文件选项卡,说明未加载System.Windows.pdb  这是它破解的代码

protected async override void OnNavigatedFrom(NavigationEventArgs e)
    {
        base.OnNavigatedFrom(e);

        // we are suppose to save the note, when user navigates away from the page
        ourNote.Note = editorTextBox.Text.Replace("\r", "\n");
        await App.ViewModel.UpdateNotes();
    }

有谁知道我错了什么? 这是NoteModel类,myNote变量属于这种类型。

public class NoteModel : INotifyPropertyChanged
{

    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(String propertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (null != handler)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    private string _id;

    public string ID 
    {
        get 
        { 
            return _id;
        }
        set 
        {
            // check to see if the value isn't the same with _id if not raise a propertychanged event via the method
            if (value != _id)
            {
                _id = value;
                NotifyPropertyChanged("ID");
            }
        } 
    }

    private string _modDate;

    public string ModifiedDate
    {
        get
        {
            return _modDate;
        }
        set
        {
            // check to see if the value isn't the same with _id if not raise a propertychanged event via the method
            if (value != _modDate)
            {
                _modDate = value;
                NotifyPropertyChanged("ModifiedDate");
            }
        }
    }

    private string _note;

    public string Note
    {
        get
        {
            return _note;
        }
        set
        {
            // check to see if the value isn't the same with _id if not raise a propertychanged event via the method
            if (value != _note)
            {
                _note = value;

                string[] lines = _note.Split('\n'); // we change this from '\r' to '\n' because of winRT serializaiton and deserialization ends up with line feeds only, removes carriage returns
                if (lines.Length > 0)
                {
                    FirstLine = lines[0]; // we removed .Replace("\n", ""); since no more carriage returns
                }
                else
                {
                    // what if there is no first line
                    FirstLine = "(empty)";
                }
                NotifyPropertyChanged("Note");
            }
        }
    }

    private string _firstLine;

    public string FirstLine
    {
        get
        {
            return _firstLine;
        }
        set
        {
            // check to see if the value isn't the same with _id if not raise a propertychanged event via the method
            if (value != _firstLine)
            {
                _firstLine = value;
                NotifyPropertyChanged("FirstLine");
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

我认为发生异常是因为未加载笔记列表页面的某些元素(返回时的页面)。

App.ViewModel.UpdateNotes()是否更新了备注列表页面的元素?如果是,您应该只更新数据,然后在OnNavigateTo页面时更新注释列表页面元素。