나는 FileOpenCore가 파일을 실제로 여는 메서드에 준 이름이라고 생각합니다. 파일 이름을 취하고 여는 모든 방법으로 바꾸십시오.
파일이 성공적으로 열릴 때마다 InsertFile 메서드가 호출됩니다 (아마도 FileOpenCore에서 호출 될 것입니다). 파일을 열려고 시도했지만 실패한 경우 RemoveFile을 호출해야합니다. 최근 파일 목록에 더 이상 존재하지 않는 파일을 보관하고 싶지는 않습니다.
<common:RecentFileList x:Name="RecentFileList" />
그리고 그가 당신의 윈도우의 생성자에서했던 것처럼 당신은 클릭 핸들러를 연결 :
그래서 당신은 당신의 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.
}
}
메뉴에 메뉴 항목을 추가했습니다. 메뉴 클릭 이벤트가 작동하지 않습니다. – Shibli