Exemplo n.º 1
0
        private void OnDeleted(object source, FileSystemEventArgs e)
        {
            int index = FileInfos.FindIndex(x => x == CurrentFileInfo); // Get the index of the current file being displayed (-1 if not found [no files])

            // Try and find the item in the list, if it's there, remote it, if not, continue
            FileInfo fi = FileInfos.Find(x => x.FullName == e.FullPath);

            FileInfos.Remove(fi);

            if (!FileInfos.Contains(CurrentFileInfo)) // is the selected file removed? If not, just continue the day
            {
                if (index >= FileInfos.Count())       // is the index above what's suppose to be?
                {
                    index = FileInfos.Count() - 1;    // Move it down a Markus Persson (Notch)
                }

                if (FileInfos.Count() > 0)              // Is there still items in the list?
                {
                    CurrentFileInfo = FileInfos[index]; // Select that file
                }
                else // No items in the list
                {
                    CurrentFileInfo = null; // Select nothing for the current file info
                }

                UpdateImage(); // update only if it's a new file
            }

            Changed(); // Something changed! (Removed a file!)
        }
Exemplo n.º 2
0
        private void DataGrid1_OnPreviewKeyDown(object sender, KeyEventArgs e)
        {
            // TODO: Find a refined way
            if (e.Key != Key.Delete)
            {
                return;
            }
            var selectedItems = DataGrid1.SelectedItems.Cast <FileInfo>().ToList();

            foreach (var item in selectedItems)
            {
                _fileInfos.Remove(item);
            }
        }