From 66895d613ea87a37cd295f5b0bd1cdd095df3879 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期四, 14 九月 2023 21:08:12 +0800 Subject: [PATCH] 添加删除功能~ --- DataLoader/Model/ViewData.cs | 19 +++++++++++++++++-- DataLoader/MainWindow.xaml.cs | 18 ++++++++++++++++++ DataLoader/MainWindow.xaml | 12 ++++++++++-- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/DataLoader/MainWindow.xaml b/DataLoader/MainWindow.xaml index e0562e6..9766d12 100644 --- a/DataLoader/MainWindow.xaml +++ b/DataLoader/MainWindow.xaml @@ -146,6 +146,7 @@ <RowDefinition Height="40"/> <RowDefinition Height="40"/> <RowDefinition Height="40"/> + <RowDefinition Height="40"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> @@ -211,7 +212,13 @@ <ListView.View> <GridView> <GridView.Columns> - <!--<GridViewColumn Header="搴忓彿" Width="50" DisplayMemberBinding="{Binding Path=ID, Mode=OneWay}"/>--> + <GridViewColumn Width="30"> + <GridViewColumn.CellTemplate> + <DataTemplate> + <CheckBox IsChecked="{Binding Path=Checked, Mode=TwoWay}" Tag="{Binding Path=ID, Mode=OneWay}" /> + </DataTemplate> + </GridViewColumn.CellTemplate> + </GridViewColumn> <GridViewColumn Header="搴忓彿" Width="Auto"> <GridViewColumn.CellTemplate> <DataTemplate> @@ -229,6 +236,7 @@ </ScrollViewer> <Button x:Name="btnLoad" Grid.Row="6" Grid.Column="4" Content="鍔� 杞�" Style="{StaticResource btn}" Click="Load_MouseLeftButtonDown"/> - <Button x:Name="btnImport" Grid.Row="7" Grid.Column="4" Content="瀵� 鍏�" Style="{StaticResource btn}" VerticalAlignment="Top" Click="Import_MouseLeftButtonDown"/> + <Button x:Name="btnDel" Grid.Row="7" Grid.Column="4" Content="鍒� 闄�" Style="{StaticResource btn}" Click="Del_MouseLeftButtonDown"/> + <Button x:Name="btnImport" Grid.Row="8" Grid.Column="4" Content="瀵� 鍏�" Style="{StaticResource btn}" VerticalAlignment="Top" Click="Import_MouseLeftButtonDown"/> </Grid> </Window> diff --git a/DataLoader/MainWindow.xaml.cs b/DataLoader/MainWindow.xaml.cs index efb818d..27ec985 100644 --- a/DataLoader/MainWindow.xaml.cs +++ b/DataLoader/MainWindow.xaml.cs @@ -10,6 +10,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Data; +using System.Windows.Forms.VisualStyles; namespace DataLoader { @@ -165,6 +166,23 @@ this.isBusy = false; } + // 鍒犻櫎 + private void Del_MouseLeftButtonDown(object sender, RoutedEventArgs e) + { + if (null == this.viewDatas || this.viewDatas.Count == 0) return; + + int i = 0; + while (i < this.viewDatas.Count) + { + if (this.viewDatas[i] != null && this.viewDatas[i].Checked) + { + this.viewDatas.RemoveAt(i); + continue; + } + i++; + } + } + // 瀵煎叆 private void Import_MouseLeftButtonDown(object sender, RoutedEventArgs e) { diff --git a/DataLoader/Model/ViewData.cs b/DataLoader/Model/ViewData.cs index b14f485..dc58063 100644 --- a/DataLoader/Model/ViewData.cs +++ b/DataLoader/Model/ViewData.cs @@ -13,11 +13,11 @@ public string Ext { set; get; } - private int _id; - public ViewData() { } + + private int _id; public int ID { @@ -35,6 +35,21 @@ } } + private bool _checked; + + public bool Checked + { + set + { + if (_checked != value) + { + _checked = value; + ChangProperty("Checked"); + } + } + get { return _checked; } + } + private string _filePath; public string FilePath -- Gitblit v1.9.3