KendoUI 官方示例之 Grid / Filter row

本文提供了KendoUI网格过滤行功能的详细示例链接,帮助开发者更好地理解和使用KendoUI的网格过滤特性。KendoUI是一个强大的UI库,适用于Web应用程序,提供了丰富的组件和API。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<Window x:Class="FengJing.Views.OtherView.PlantList" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:FengJing.Views.OtherView" mc:Ignorable="d" Title="苗木信息管理" Height="600" Width="1200" WindowStartupLocation="CenterScreen"> <Window.Resources> <!-- 按钮样式 --> <Style TargetType="Button" x:Key="ActionButton"> <Setter Property="Margin" Value="2"/> <Setter Property="Padding" Value="5,2"/> <Setter Property="MinWidth" Value="60"/> </Style> <!-- 搜索框样式 --> <Style TargetType="TextBox" x:Key="SearchBox"> <Setter Property="Margin" Value="5"/> <Setter Property="Padding" Value="5"/> <Setter Property="MinWidth" Value="200"/> </Style> <!-- 数据网格样式 --> <Style TargetType="DataGrid"> <Setter Property="Margin" Value="10"/> <Setter Property="AutoGenerateColumns" Value="False"/> <Setter Property="CanUserAddRows" Value="False"/> <Setter Property="CanUserDeleteRows" Value="False"/> <Setter Property="SelectionMode" Value="Single"/> <Setter Property="IsReadOnly" Value="True"/> <Setter Property="RowHeaderWidth" Value="0"/> <Setter Property="VerticalScrollBarVisibility" Value="Auto"/> <Setter Property="HorizontalScrollBarVisibility" Value="Auto"/> </Style> <!-- 数字列样式 --> <Style TargetType="DataGridTextColumn"> <Setter Property="ElementStyle"> <Setter.Value> <Style TargetType="TextBlock"> <Setter Property="HorizontalAlignment" Value="Right"/> <Setter Property="Margin" Value="0,0,10,0"/> </Style> </Setter.Value> </Setter> </Style> <!-- 新增:搜索区域折叠/展开动画 --> <Storyboard x:Key="ExpandSearchPanel" Duration="0:0:0.3"> <DoubleAnimation Storyboard.TargetProperty="Height" From="0" To="{Binding ElementName=SearchPanel, Path=DesiredHeight}" DecelerationRatio="0.9"/> </Storyboard> <Storyboard x:Key="CollapseSearchPanel" Duration="0:0:0.3"> <DoubleAnimation Storyboard.TargetProperty="Height" From="{Binding ElementName=SearchPanel, Path=ActualHeight}" To="0" AccelerationRatio="0.9"/> </Storyboard> </Window.Resources> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <!-- 状态栏 --> </Grid.RowDefinitions> <!-- 工具栏 --> <StackPanel Orientation="Horizontal" Margin="10" Grid.Row="0"> <Button Content="添加苗木" Command="{Binding AddPlantCommand}" Style="{StaticResource ActionButton}" Background="#4CAF50" Foreground="White" Click="Button_Click_Create" Height="33.24"/> <Button Content="刷新列表" Command="{Binding RefreshCommand}" Style="{StaticResource ActionButton}" Height="33.24"/> <Button x:Name="btnPreciseSearch" Content="精确搜索" Click="ToggleSearchPanel" Style="{StaticResource ActionButton}" Margin="5,0,0,0" Height="33.24" Background="#2196F3" Foreground="White"/> <Button Content="导入苗木列表" Command="{Binding ImportCommand}" Style="{StaticResource ActionButton}" Margin="5,0,0,0" Height="33.24" Background="#2196F3" Foreground="White"/> </StackPanel> <!-- 精确搜索条件区域 - 初始折叠 --> <Border x:Name="SearchPanel" Grid.Row="1" Margin="10,0,10,10" Padding="10" BorderBrush="#CCCCCC" BorderThickness="1" Background="#F5F5F5" Height="0" VerticalAlignment="Top"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <!-- 第一行 --> <TextBlock Text="苗木名称:" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Margin="5"/> <TextBox Text="{Binding SearchName, UpdateSourceTrigger=PropertyChanged}" Grid.Row="0" Grid.Column="1" Margin="5" MinWidth="100"/> <TextBlock Text="类型:" Grid.Row="0" Grid.Column="2" VerticalAlignment="Center" Margin="5"/> <TextBox Text="{Binding SearchType, UpdateSourceTrigger=PropertyChanged}" Grid.Row="0" Grid.Column="3" Margin="5" MinWidth="100"/> <TextBlock Text="颜色:" Grid.Row="0" Grid.Column="4" VerticalAlignment="Center" Margin="5"/> <TextBox Text="{Binding SearchColor, UpdateSourceTrigger=PropertyChanged}" Grid.Row="0" Grid.Column="5" Margin="5" MinWidth="100"/> <TextBlock Text="单位:" Grid.Row="0" Grid.Column="6" VerticalAlignment="Center" Margin="5"/> <TextBox Text="{Binding SearchUnit, UpdateSourceTrigger=PropertyChanged}" Grid.Row="0" Grid.Column="7" Margin="5" MinWidth="100"/> <!-- 第二行 --> <TextBlock Text="适生地区:" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" Margin="5"/> <TextBox Text="{Binding SearchSuitableRegion, UpdateSourceTrigger=PropertyChanged}" Grid.Row="1" Grid.Column="1" Margin="5" MinWidth="100"/> <TextBlock Text="生长习性:" Grid.Row="1" Grid.Column="2" VerticalAlignment="Center" Margin="5"/> <TextBox Text="{Binding SearchHabit, UpdateSourceTrigger=PropertyChanged}" Grid.Row="1" Grid.Column="3" Margin="5" MinWidth="100"/> <TextBlock Text="耐湿耐旱性:" Grid.Row="1" Grid.Column="4" VerticalAlignment="Center" Margin="5"/> <TextBox Text="{Binding SearchWetDroughtTolerance, UpdateSourceTrigger=PropertyChanged}" Grid.Row="1" Grid.Column="5" Margin="5" MinWidth="100"/> <TextBlock Text="是否海绵类:" Grid.Row="1" Grid.Column="6" VerticalAlignment="Center" Margin="5"/> <TextBox Text="{Binding SearchIsSpongePlant, UpdateSourceTrigger=PropertyChanged}" Grid.Row="1" Grid.Column="7" Margin="5" MinWidth="100"/> <!-- 第三行 --> <TextBlock Text="常绿落叶性:" Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" Margin="5"/> <TextBox Text="{Binding SearchEvergreenDeciduous, UpdateSourceTrigger=PropertyChanged}" Grid.Row="2" Grid.Column="1" Margin="5" MinWidth="100"/> <TextBlock Text="观赏价值:" Grid.Row="2" Grid.Column="2" VerticalAlignment="Center" Margin="5"/> <TextBox Text="{Binding SearchOrnamentalValue, UpdateSourceTrigger=PropertyChanged}" Grid.Row="2" Grid.Column="3" Margin="5" MinWidth="100"/> <TextBlock Text="色叶期:" Grid.Row="2" Grid.Column="4" VerticalAlignment="Center" Margin="5"/> <TextBox Text="{Binding SearchColorPeriod, UpdateSourceTrigger=PropertyChanged}" Grid.Row="2" Grid.Column="5" Margin="5" MinWidth="100"/> <TextBlock Text="胸径/地径(cm):" Grid.Row="2" Grid.Column="6" VerticalAlignment="Center" Margin="5"/> <TextBox Text="{Binding SearchDiameter, UpdateSourceTrigger=PropertyChanged}" Grid.Row="2" Grid.Column="7" Margin="5" MinWidth="100"/> <!-- 第四行 --> <TextBlock Text="高度(cm):" Grid.Row="3" Grid.Column="0" VerticalAlignment="Center" Margin="5"/> <TextBox Text="{Binding SearchHeight, UpdateSourceTrigger=PropertyChanged}" Grid.Row="3" Grid.Column="1" Margin="5" MinWidth="100"/> <TextBlock Text="冠幅(cm):" Grid.Row="3" Grid.Column="2" VerticalAlignment="Center" Margin="5"/> <TextBox Text="{Binding SearchCrownWidth, UpdateSourceTrigger=PropertyChanged}" Grid.Row="3" Grid.Column="3" Margin="5" MinWidth="100"/> <TextBlock Text="信息价(元):" Grid.Row="3" Grid.Column="4" VerticalAlignment="Center" Margin="5"/> <TextBox Text="{Binding SearchPrice, UpdateSourceTrigger=PropertyChanged}" Grid.Row="3" Grid.Column="5" Margin="5" MinWidth="100"/> <StackPanel Orientation="Horizontal" Grid.Row="3" Grid.Column="7" HorizontalAlignment="Right"> <Button Content="搜索" Command="{Binding SearchCommand}" Style="{StaticResource ActionButton}" Margin="5" Width="80" Background="#4CAF50" Foreground="White"/> <Button Content="清除条件" Command="{Binding ClearSearchCommand}" Style="{StaticResource ActionButton}" Margin="5" Width="80"/> </StackPanel> </Grid> </Border> <!-- 数据网格 --> <DataGrid x:Name="PlantDataGrid" ItemsSource="{Binding Plants}" Grid.Row="1" SelectedItem="{Binding SelectedPlant}"> <DataGrid.Columns> <DataGridTextColumn Header="序号" Binding="{Binding Id}" Width="60"/> <DataGridTextColumn Header="苗木名称" Binding="{Binding Name}" Width="100"/> <DataGridTextColumn Header="类型" Binding="{Binding Type}" Width="60"/> <DataGridTextColumn Header="颜色" Binding="{Binding Color}" Width="60"/> <DataGridTextColumn Header="单位" Binding="{Binding Unit}" Width="60"/> <DataGridTextColumn Header="适生地区" Binding="{Binding SuitableRegion}" Width="120"/> <DataGridTextColumn Header="生长习性" Binding="{Binding Habit}" Width="120"/> <DataGridTextColumn Header="奈湿奈旱性" Binding="{Binding WetDroughtTolerance}" Width="70"/> <DataGridTextColumn Header="是否海绵类" Binding="{Binding IsSpongePlant}" Width="70"/> <DataGridTextColumn Header="常绿落叶性" Binding="{Binding EvergreenDeciduous}" Width="80"/> <DataGridTextColumn Header="观赏价值" Binding="{Binding OrnamentalValue}" Width="80"/> <DataGridTextColumn Header="色叶期" Binding="{Binding ColorPeriod}" Width="70"/> <DataGridTextColumn Header="胸径/地径(cm)" Binding="{Binding Diameter, StringFormat={}{0:F2}}" Width="100"/> <DataGridTextColumn Header="高度(cm)" Binding="{Binding Height, StringFormat={}{0:F2}}" Width="80"/> <DataGridTextColumn Header="冠幅(cm)" Binding="{Binding CrownWidth, StringFormat={}{0:F2}}" Width="80"/> <DataGridTextColumn Header="信息价(元)" Binding="{Binding Price, StringFormat={}{0:N2}}" Width="100"/> <DataGridTextColumn Header="创建时间" Binding="{Binding CreateAt, StringFormat=yyyy-MM-dd HH:mm:ss}" Width="130"/> <DataGridTextColumn Header="更新时间" Binding="{Binding LastUpdatedAt, StringFormat=yyyy-MM-dd HH:mm:ss}" Width="130"/> <!-- 操作列 --> <DataGridTemplateColumn Header="操作" Width="190"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <!-- 新增的查看图片按钮 --> <Button Content="查看图片" Command="{Binding DataContext.ViewImageCommand, RelativeSource={RelativeSource AncestorType=DataGrid}}" CommandParameter="{Binding}" Style="{StaticResource ActionButton}" Background="#4CAF50" Foreground="White" Margin="0,0,5,0"/> <Button Content="编辑" Command="{Binding DataContext.EditPlantCommand, RelativeSource={RelativeSource AncestorType=DataGrid}}" CommandParameter="{Binding}" Style="{StaticResource ActionButton}" Background="#2196F3" Foreground="White"/> <Button Content="删除" Command="{Binding DataContext.DeletePlantCommand, RelativeSource={RelativeSource AncestorType=DataGrid}}" CommandParameter="{Binding}" Style="{StaticResource ActionButton}" Background="#F44336" Foreground="White"/> </StackPanel> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> </DataGrid.Columns> </DataGrid> <!-- 分页控制 --> <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Grid.Row="2" Margin="0,10"> <Button Content="首页" Command="{Binding FirstPageCommand}" Style="{StaticResource ActionButton}"/> <Button Content="上一页" Command="{Binding PreviousPageCommand}" Style="{StaticResource ActionButton}"/> <TextBlock Text="{Binding CurrentPage, StringFormat='第 {0} 页'}" VerticalAlignment="Center" Margin="10,0"/> <Button Content="下一页" Command="{Binding NextPageCommand}" Style="{StaticResource ActionButton}"/> <Button Content="末页" Command="{Binding LastPageCommand}" Style="{StaticResource ActionButton}"/> <TextBlock Text="每页数量:" VerticalAlignment="Center" Margin="10,0,5,0"/> <ComboBox ItemsSource="{Binding PageSizeOptions}" SelectedItem="{Binding PageSize}" Width="80" Margin="0,0,10,0"/> <TextBlock Text="{Binding TotalCount, StringFormat='共 {0} 条记录'}" VerticalAlignment="Center"/> </StackPanel> <!-- 状态栏 --> <StatusBar Grid.Row="2" VerticalAlignment="Bottom"> <StatusBarItem> <TextBlock Text="{Binding StatusMessage}"/> </StatusBarItem> </StatusBar> </Grid> </Window> 前端代码如上 using Autodesk.AutoCAD.Windows.Data; using FengJing.Views.OtherView; using GalaSoft.MvvmLight.Command; using OfficeOpenXml; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Data.Entity; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; namespace FengJing.Services.PlantLibModule { public static class PlantImportService { public static List<Plant> ImportFromFile(string filePath) { var plants = new List<Plant>(); if (filePath.EndsWith(".xlsx") || filePath.EndsWith(".xls")) { // 使用 EPPlus 或其他库处理 Excel using (var package = new ExcelPackage(new FileInfo(filePath))) { // 检查工作簿中是否有工作表 if (package.Workbook.Worksheets.Count == 0) { throw new ApplicationException("Excel文件中不包含任何工作表"); } var worksheet = package.Workbook.Worksheets[1]; int rowCount = worksheet.Dimension.Rows; for (int row = 2; row <= rowCount; row++) // 第一行是标题 { plants.Add(new Plant { Name = worksheet.Cells[row, 1].Text, Type = new PlantType{ Name = worksheet.Cells[row, 2].Text }, SuitableRegion = new SuitableRegionrClass { CityName = worksheet.Cells[row, 3].Text }, EvergreenDeciduous = new EvergreenDeciduousClass { EvergreenName = worksheet.Cells[row, 4].Text }, OrnamentalValue = new OrnamentalValueClass { OrnamentalValueName = worksheet.Cells[row, 5].Text }, Price = decimal.Parse(worksheet.Cells[row, 6].Text), ColorPeriod = new ColorPeriodClass { ColorPeriodName = worksheet.Cells[row, 7].Text }, Color = new ColorClass { ColorName = worksheet.Cells[row, 8].Text }, Unit = new customUnitClass { UnitName = worksheet.Cells[row, 9].Text }, Diameter = double.Parse(worksheet.Cells[row, 10].Text), CrownWidth = double.Parse(worksheet.Cells[row, 11].Text), Height = double.Parse(worksheet.Cells[row, 12].Text), PlantingDensity = double.Parse(worksheet.Cells[row, 13].Text), Habit = worksheet.Cells[row, 14].Text, WetDroughtTolerance = worksheet.Cells[row, 15].Text, IsSpongePlant = worksheet.Cells[row, 16].Text, CreateAt = DateTime.Now }); } } } //else if (filePath.EndsWith(".csv")) //{ // // 使用 CsvHelper 或 StreamReader 处理 CSV // var lines = File.ReadAllLines(filePath); // for (int i = 1; i < lines.Length; i++) // 跳过标题行 // { // var values = lines[i].Split(','); // plants.Add(new Plant // { // Name = values[0], // Category = values[1], // Price = decimal.Parse(values[2]), // // 其他属性... // }); // } //} return plants; } } public class PlantListViewModel { // 搜索条件属性 public string SearchName { get; set; } public string SearchType { get; set; } public string SearchColor { get; set; } public string SearchUnit { get; set; } public string SearchSuitableRegion { get; set; } public string SearchHabit { get; set; } public string SearchWetDroughtTolerance { get; set; } public string SearchIsSpongePlant { get; set; } public string SearchEvergreenDeciduous { get; set; } public string SearchOrnamentalValue { get; set; } public string SearchColorPeriod { get; set; } public string SearchDiameter { get; set; } public string SearchHeight { get; set; } public string SearchCrownWidth { get; set; } public string SearchPrice { get; set; } private readonly plantService _plantService = new plantService(); // 分页相关属性 private int _currentPage = 1; private int _pageSize = 20; private int _totalCount; private string _searchText; public string SearchText { get => _searchText; set { _searchText = value; OnPropertyChanged(); } } public ObservableCollection<Plant> Plants { get; } = new ObservableCollection<Plant>(); public Plant SelectedPlant { get; set; } public int CurrentPage { get => _currentPage; set => SetField(ref _currentPage, value); } public int PageSize { get => _pageSize; set { if (SetField(ref _pageSize, value)) { LoadPlants(); } } } public List<int> PageSizeOptions { get; } = new List<int> { 10, 20, 50, 100 }; public int TotalCount { get => _totalCount; set => SetField(ref _totalCount, value); } public string StatusMessage { get; set; } // 命令 public ICommand AddPlantCommand { get; } public ICommand EditPlantCommand { get; } public ICommand DeletePlantCommand { get; } public ICommand RefreshCommand { get; } //public ICommand SearchCommand { get; } public ICommand FirstPageCommand { get; } public ICommand PreviousPageCommand { get; } public ICommand NextPageCommand { get; } public ICommand LastPageCommand { get; } public ICommand ImportCommand { get; } public ICommand ViewImageCommand { get; } public ICommand SearchCommand { get; } public ICommand ClearSearchCommand { get; } public PlantListViewModel() { // 初始化命令 AddPlantCommand = new RelayCommand(AddPlant); EditPlantCommand = new RelayCommand<Plant>(EditPlant); DeletePlantCommand = new RelayCommand<Plant>(DeletePlant); RefreshCommand = new RelayCommand(LoadPlants); SearchCommand = new RelayCommand(ExecuteSearch); ClearSearchCommand = new RelayCommand(ClearSearchConditions); FirstPageCommand = new RelayCommand(() => ChangePage(1)); PreviousPageCommand = new RelayCommand(() => ChangePage(CurrentPage - 1)); NextPageCommand = new RelayCommand(() => ChangePage(CurrentPage + 1)); LastPageCommand = new RelayCommand(() => ChangePage(TotalPages)); ImportCommand = new RelayCommand(ImportPlants); ViewImageCommand = new RelayCommand<Plant>(ShowPlantImage); // 加载数据 LoadPlants(); } private int TotalPages => (int)Math.Ceiling((double)TotalCount / PageSize); private void LoadPlants() { try { var result = _plantService.GetPlants(CurrentPage, PageSize, SearchText); Plants.Clear(); foreach (var plant in result.Plants) { Plants.Add(plant); } TotalCount = result.TotalCount; StatusMessage = $"成功加载 {Plants.Count} 条苗木记录"; } catch (Exception ex) { StatusMessage = $"加载失败: {ex.Message}"; } } private void SearchPlants() { CurrentPage = 1; LoadPlants(); } private void ChangePage(int page) { if (page < 1 || page > TotalPages) return; CurrentPage = page; LoadPlants(); } private void AddPlant() { var createWindow = new CreatePlant(); // 安全访问 Application.Current if (Application.Current != null) { createWindow.Owner = Application.Current.MainWindow; } else { // 处理非 WPF 环境的情况 createWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen; } createWindow.ShowDialog(); // 添加完成后刷新列表 LoadPlants(); } private void ShowPlantImage(Plant plant) { if (plant == null) return; var showImageWindow = new ImageShow(plant); Autodesk.AutoCAD.ApplicationServices.Application.ShowModalWindow(showImageWindow); } private void EditPlant(Plant plant) { if (plant == null) return; var updateWindow = new UpdatePlant(plant); Autodesk.AutoCAD.ApplicationServices.Application.ShowModalWindow(updateWindow); // 更新完成后刷新列表 LoadPlants(); } private void DeletePlant(Plant plant) { if (plant == null) return; var result = MessageBox.Show($"确定要删除苗木 '{plant.Name}' 吗?", "确认删除", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (result == MessageBoxResult.Yes) { try { bool success = _plantService.DeletePlant(plant.Id); if (success) { StatusMessage = $"苗木 '{plant.Name}' 已删除"; LoadPlants(); } else { StatusMessage = "删除失败"; } } catch (Exception ex) { StatusMessage = $"删除失败: {ex.Message}"; } } } // 导入方法实现 private void ImportPlants() { try { // 创建打开文件对话框 var openFileDialog = new Microsoft.Win32.OpenFileDialog { Filter = "Excel 文件|*.xlsx;*.xls|CSV 文件|*.csv|所有文件|*.*", Title = "选择苗木列表文件" }; if (openFileDialog.ShowDialog() == true) { string filePath = openFileDialog.FileName; // 调用导入逻辑 var importedPlants = PlantImportService.ImportFromFile(filePath); // 处理导入的数据(示例) foreach (var plant in importedPlants) { // 保存到数据库 plantService pService = new plantService(); bool bSave = pService.AddPlant(plant); } // 刷新列表 LoadPlants(); MessageBox.Show($"成功导入 {importedPlants.Count} 条苗木记录"); } } catch (Exception ex) { MessageBox.Show($"导入失败: {ex.Message}"); } } // 执行搜索 private void ExecuteSearch() { var query = dbContext.Plants.AsQueryable(); // 根据条件进行精确搜索 if (!string.IsNullOrEmpty(SearchName)) query = query.Where(p => p.Name == SearchName); if (!string.IsNullOrEmpty(SearchType)) query = query.Where(p => p.Type == SearchType); if (!string.IsNullOrEmpty(SearchColor)) query = query.Where(p => p.Color == SearchColor); // 同样处理其他条件... // 处理数值类型条件 if (!string.IsNullOrEmpty(SearchDiameter)) { if (double.TryParse(SearchDiameter, out var diameter)) query = query.Where(p => p.Diameter == diameter); } if (!string.IsNullOrEmpty(SearchHeight)) { if (double.TryParse(SearchHeight, out var height)) query = query.Where(p => p.Height == height); } if (!string.IsNullOrEmpty(SearchPrice)) { if (decimal.TryParse(SearchPrice, out var price)) query = query.Where(p => p.Price == price); } // 应用分页 TotalCount = query.Count(); Plants = new ObservableCollection<Plant>(query .Skip((CurrentPage - 1) * PageSize) .Take(PageSize) .ToList()); } // 清除搜索条件 private void ClearSearchConditions() { SearchName = ""; SearchType = ""; SearchColor = ""; SearchUnit = ""; SearchSuitableRegion = ""; SearchHabit = ""; SearchWetDroughtTolerance = ""; SearchIsSpongePlant = ""; SearchEvergreenDeciduous = ""; SearchOrnamentalValue = ""; SearchColorPeriod = ""; SearchDiameter = ""; SearchHeight = ""; SearchCrownWidth = ""; SearchPrice = ""; // 通知所有属性已更改 OnPropertyChanged(nameof(SearchName)); OnPropertyChanged(nameof(SearchType)); OnPropertyChanged(nameof(SearchColor)); OnPropertyChanged(nameof(SearchUnit)); OnPropertyChanged(nameof(SearchSuitableRegion)); OnPropertyChanged(nameof(SearchHabit)); OnPropertyChanged(nameof(SearchWetDroughtTolerance)); OnPropertyChanged(nameof(SearchIsSpongePlant)); OnPropertyChanged(nameof(SearchEvergreenDeciduous)); OnPropertyChanged(nameof(SearchOrnamentalValue)); OnPropertyChanged(nameof(SearchColorPeriod)); OnPropertyChanged(nameof(SearchDiameter)); OnPropertyChanged(nameof(SearchHeight)); OnPropertyChanged(nameof(SearchCrownWidth)); OnPropertyChanged(nameof(SearchPrice)); // 清除后重新加载数据 LoadPlants(); } // INotifyPropertyChanged 实现 public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } protected bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null) { if (EqualityComparer<T>.Default.Equals(field, value)) return false; field = value; OnPropertyChanged(propertyName); return true; } } } 后端代码如上,怎么适配一下
最新发布
07-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值