private void Backstage_PopulateRecentFiles() { List <string> paths = RecentFiles.GetFileNames(); dpRecentFiles.Children.Clear(); foreach (string path in paths) { try { RecentFileButton button = new RecentFileButton { DirPath = Path.GetDirectoryName(path), FileName = Path.GetFileName(path), IsEnabled = File.Exists(path), Tag = path, ToolTip = path }; DockPanel.SetDock(button, Dock.Top); dpRecentFiles.Children.Add(button); } catch (Exception ex) { if (ex is ArgumentException) { // Path is apparently invalid path RecentFiles.Remove(path); } } } }
private void Backstage_CmdRecentFileRemove_Executed(object sender, ExecutedRoutedEventArgs evt) { if (evt.Source is RecentFileButton button) { RecentFiles.Remove((string)button.Tag); Backstage_PopulateRecentFiles(); } }
private void Backstage_CleanRecentFiles() { foreach (UIElement element in dpRecentFiles.Children) { if (element is RecentFileButton button) { if (!button.IsEnabled) { RecentFiles.Remove((string)button.Tag); } } } }