Browse Source

compdfkit(win) - 批量移除和取消选中

weixiangjie 1 year ago
parent
commit
ed522eb9e2

+ 2 - 2
Demo/Examples/Compdfkit_Tools/Encryption/FileGridListControl.xaml

@@ -43,7 +43,7 @@
                  <Grid Grid.Row="0">
                      <DataGrid Background="White" BorderBrush="#E6E6E6" x:Name="FileDataGrid" HeadersVisibility="Column"
                                IsReadOnly="True" AutoGenerateColumns="False" FontSize="14" SelectionMode="Extended" Height="270"
-                               ScrollViewer.CanContentScroll="False" HorizontalScrollBarVisibility="Auto">
+                               ScrollViewer.CanContentScroll="False" HorizontalScrollBarVisibility="Auto" MouseLeftButtonDown="FileDataGrid_OnMouseLeftButtonUp" SelectionChanged="FileDataGrid_SelectionChanged">
                          <DataGrid.Columns>
                              <DataGridTextColumn Header="File" Width="*" Binding="{Binding FileName}" />
                              <DataGridTextColumn Header="Size" Width="*" Binding="{Binding Size}" />
@@ -74,7 +74,7 @@
                          </DataGrid.Resources>
                      </DataGrid>
                 </Grid>
-                <Button Grid.Row="1" FontFamily="Segoe UI" FontSize="14" Content="Remove" Width="112" Height="32" HorizontalAlignment="Left" Click="Remove_Click"></Button>
+                <Button Grid.Row="1" x:Name="BtnRemove" FontFamily="Segoe UI" FontSize="14" Content="Remove All" Width="112" Height="32" HorizontalAlignment="Left" Click="Remove_Click"></Button>
             </Grid>
         </Border>
     </Grid>

+ 21 - 0
Demo/Examples/Compdfkit_Tools/Encryption/FileGridListControl.xaml.cs

@@ -7,6 +7,7 @@ using System.Linq;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Data;
+using System.Windows.Input;
 using Microsoft.Win32;
 
 namespace Compdfkit_Tools.PDFControl
@@ -94,8 +95,15 @@ namespace Compdfkit_Tools.PDFControl
 
         private void Remove_Click(object sender, RoutedEventArgs e)
         {
+            if (FileDataGrid.SelectedItems.Count == 0)
+            {
+                FileInfoDataList.Clear();
+                OnPropertyChanged("FileNum");
+                return;
+            }
             var selectedItems = FileDataGrid.SelectedItems;
             var selectedItemsList = selectedItems.Cast<FileInfoData>().ToList();
+            
             foreach (var item in selectedItemsList)
             {
                 FileInfoDataList.Remove(item);
@@ -107,5 +115,18 @@ namespace Compdfkit_Tools.PDFControl
         {
             PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
         }
+
+        private void FileDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            BtnRemove.Content = FileDataGrid.SelectedItems.Count > 0 ? "Remove" : "Remove All";
+        }
+
+        private void FileDataGrid_OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
+        {
+            if (e.OriginalSource.GetType() != typeof(DataGridCell))
+            {
+                FileDataGrid.UnselectAll();
+            }
+        }
     }
 }