An exception of type 'System.Reflection.TargetInvocation
本文关键字:System Reflection TargetInvocation exception of type An | 更新日期: 2023-09-27 18:10:43
我正在构建一个笔记应用程序。在笔记编辑页面上,当用户创建新的笔记和文本类型时,然后按手机的返回按钮,代码应该创建一个新的笔记,我尝试用新行替换回车。当我在应用中尝试这个时,我得到这个异常。类型为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();
}
有谁知道我错了什么吗?这是notemmodel类,ourNote变量就是这种类型。
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");
}
}
}
}
我认为发生异常是因为你的笔记列表页面(当你回来的页面)的一些元素没有加载。
App.ViewModel.UpdateNotes()更新你的笔记列表页面的元素吗?如果是,你应该只更新数据,然后更新笔记列表页面元素当你OnNavigateTo页面