我相信 FileOpenCore 是作者给实际打开文件的方法的名称。将其替换为您拥有的任何采用文件名并打开它的方法。
只要文件成功打开,就会调用 InsertFile 方法(可能在您的 FileOpenCore 中)。如果您尝试打开文件但失败,则应调用 RemoveFile。例如,您不想保留最近文件列表中不再存在的文件。
因此,如果您像作者那样定义了您的 RecentFileList:
<common:RecentFileList x:Name="RecentFileList" />
然后像他在窗口的构造函数中那样连接点击处理程序:
RecentFileList.MenuClick += ( s, e ) => FileOpenCore( e.Filepath );
您的 FileOpenCore(或任何您想调用的名称)可能看起来像这样(伪代码):
private void FileOpenCore(string filename)
{
try
{
// read your file
// and do whatever processing you need
// ...
// if open was successful
RecentFileList.InsertFile(filename);
}
catch (Exception e)
{
// opening the file failed - maybe it doesn't exist anymore
// or maybe it's corrupted
RecentFileList.RemoveFile(filename);
// Do whatever other error processing you want to do.
}
}