// Delete sub-menu opening
        private void MenuItemDelete_SubmenuOpening(object sender, RoutedEventArgs e)
        {
            try
            {
                // Temporarily set the DeleteFlag search term so that it will be used to chec for DeleteFlag = true
                SearchTerm currentSearchTerm = this.DataHandler.FileDatabase.CustomSelection.SearchTerms.First(term => term.DataLabel == Constant.DatabaseColumn.DeleteFlag);
                SearchTerm tempSearchTerm    = currentSearchTerm.Clone();
                currentSearchTerm.DatabaseValue   = "true";
                currentSearchTerm.UseForSearching = true;
                currentSearchTerm.Operator        = "=";

                //bool deletedImages = this.DataHandler.FileDatabase.ExistsRowThatMatchesSelectionForAllFilesOrConstrainedRelativePathFiles(FileSelectionEnum.MarkedForDeletion);
                //bool deletedImages = this.DataHandler.FileDatabase.CountAllFilesMatchingSelectionCondition(FileSelectionEnum.Custom) > 0;
                bool deletedImages = this.DataHandler.FileDatabase.ExistsFilesMatchingSelectionCondition(FileSelectionEnum.Custom);

                // Reset  the DeleteFlag search term to its previous values
                currentSearchTerm.DatabaseValue   = tempSearchTerm.DatabaseValue;
                currentSearchTerm.UseForSearching = tempSearchTerm.UseForSearching;
                currentSearchTerm.Operator        = tempSearchTerm.Operator;

                this.MenuItemDeleteFiles.IsEnabled        = deletedImages;
                this.MenuItemDeleteFilesAndData.IsEnabled = deletedImages;
                this.MenuItemDeleteFilesData.IsEnabled    = deletedImages;

                // Enable the delete current file option only if we are not on the thumbnail grid
                this.MenuItemDeleteCurrentFileAndData.IsEnabled = this.MarkableCanvas.IsThumbnailGridVisible == false; // Only show this option if the thumbnail grid is visible
                this.MenuItemDeleteCurrentFile.IsEnabled        = this.MarkableCanvas.IsThumbnailGridVisible == false && this.DataHandler.ImageCache.Current.IsDisplayable(this.FolderPath);
                this.MenuItemDeleteCurrentData.IsEnabled        = this.MarkableCanvas.IsThumbnailGridVisible == false;
            }
            catch (Exception exception)
            {
                TracePrint.PrintMessage(String.Format("Delete submenu failed to open in Delete_SubmenuOpening. {0}", exception.ToString()));

                // This function was blowing up on one user's machine, but not others.
                // I couldn't figure out why, so I just put this fallback in here to catch that unusual case.
                this.MenuItemDeleteFiles.IsEnabled              = true;
                this.MenuItemDeleteFilesAndData.IsEnabled       = true;
                this.MenuItemDeleteFilesData.IsEnabled          = true;
                this.MenuItemDeleteCurrentFile.IsEnabled        = true;
                this.MenuItemDeleteCurrentFileAndData.IsEnabled = true;
                this.MenuItemDeleteCurrentData.IsEnabled        = true;
            }
        }