最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

WPF實(shí)現(xiàn)帶模糊搜索的DataGrid的示例代碼

 更新時(shí)間:2023年02月16日 08:27:53   作者:干杯Archer、  
這篇文章主要為大家詳細(xì)介紹了WPF如何實(shí)現(xiàn)帶模糊搜索的DataGrid,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,需要的可以參考一下

帶模糊搜索的DataGrid

前端代碼 view

<Window
    x:Class="MVVM.Views.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:hc="https://handyorg.github.io/handycontrol"
    xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
    xmlns:prism="http://prismlibrary.com/"
    Title="{Binding Title}"
    Width="525"
    Height="350"
    prism:ViewModelLocator.AutoWireViewModel="True">
    <Grid>
        <DataGrid
            Name="dataGrid"
            AutoGenerateColumns="False"
            CanUserDeleteRows="True"
            ItemsSource="{Binding CollectionView}">
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding Id}" Header="Id" />
                <DataGridTextColumn Binding="{Binding FirstName}" Header="FirstName" />
                <DataGridTextColumn Binding="{Binding LastName}" Header="LastName" />
                <DataGridTextColumn Binding="{Binding Birthday}" Header="Birthday" />
                <DataGridTextColumn Binding="{Binding Salay}" Header="Salay" />
            </DataGrid.Columns>
        </DataGrid>
        <Grid VerticalAlignment="Bottom">
            <StackPanel Orientation="Horizontal">
                <Button
                    Width="120"
                    Command="{Binding AddEmployeeCommand}"
                    Content="New Employee" />
                <hc:TextBox
                    Name="filterTextBox"
                    Width="200"
                    Margin="5,0"
                    hc:InfoElement.Placeholder="Filter data by name"
                    Text="{Binding FilterText, UpdateSourceTrigger=PropertyChanged}" />
            </StackPanel>
        </Grid>
    </Grid>
</Window>

后端代碼 ViewModel

using Prism.Commands;
using Prism.Mvvm;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Data;
using 帶篩選的DataGrid.Core;

namespace MVVM.ViewModels
{
    public class MainWindowViewModel : BindableBase
    {
        public MainWindowViewModel()
        {
            AddEmployeeCommand = new DelegateCommand(AddEmployee);
            this.employees = new List<Employee>(Employee.FakeMany(10));
            CollectionView = CollectionViewSource.GetDefaultView(employees);
            CollectionView.Filter = (item) =>
            {
                if (string.IsNullOrEmpty(FilterText)) return true;
                var em = item as Employee;
                return em.FirstName.Contains(FilterText) || em.LastName.Contains(FilterText);
            };
        }

        List<Employee> employees;
        public DelegateCommand AddEmployeeCommand { get; set; }

        private ICollectionView collectionView;
        public ICollectionView CollectionView
        {
            get { return collectionView; }
            set { SetProperty(ref collectionView, value); }
        }

        private string filterText;
        public string FilterText
        {
            get { return filterText; }
            set { SetProperty(ref filterText, value,OnFilterTextChanged); }
        }

        public void OnFilterTextChanged()
        {
            CollectionView.Refresh();
        }

        public void AddEmployee()
        {
            employees.Add(Employee.FakeOne());
            CollectionView.Refresh();
        }
    }
}

Model 代碼,引用了 Faker 這個(gè)庫(kù)來(lái)創(chuàng)造假數(shù)據(jù)

using Bogus;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 帶篩選的DataGrid.Core
{
    public class Employee
    {
        public int Id { get; set; }
        public string  FirstName { get; set; }
        public string LastName { get; set; }
        public DateOnly Birthday { get; set; }
        public int Salay { get; set; }

        public static Employee FakeOne() => employeeFaker.Generate();

        public static IEnumerable< Employee> FakeMany(int count ) => employeeFaker.Generate(count);


        private static readonly Faker<Employee> employeeFaker = new Faker<Employee>()
            .RuleFor(x => x.Id, x => x.IndexFaker)
            .RuleFor(x => x.FirstName, x => x.Person.FirstName)
            .RuleFor(x => x.LastName, x => x.Person.LastName)
            .RuleFor(x => x.Birthday, x => DateOnly.FromDateTime(x.Person.DateOfBirth))
            .RuleFor(x => x.Salay, x => x.Random.Int(6, 30) * 1000);
    }
}

代碼:https://github.com/sw554227643/---DataGrid-MVVM--

到此這篇關(guān)于WPF實(shí)現(xiàn)帶模糊搜索的DataGrid的示例代碼的文章就介紹到這了,更多相關(guān)WPF模糊搜索DataGrid內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • C#刪除UL LI中指定標(biāo)簽里文字的方法

    C#刪除UL LI中指定標(biāo)簽里文字的方法

    這篇文章主要介紹了C#刪除UL LI中指定標(biāo)簽里文字的方法,涉及C#針對(duì)頁(yè)面HTML元素進(jìn)行正則匹配與替換的相關(guān)操作技巧,需要的朋友可以參考下
    2017-05-05
  • c#和javascript函數(shù)相互調(diào)用示例分享

    c#和javascript函數(shù)相互調(diào)用示例分享

    在webBrowser使用過(guò)程中為了C#和JS通訊,webBrowser必須設(shè)置ObjectForScripting的屬性,它是一個(gè)object,這個(gè)object可以提供給webBrowser控件載入的網(wǎng)頁(yè)上的script訪問(wèn)
    2014-01-01
  • 在C#中使用指針的示例代碼

    在C#中使用指針的示例代碼

    C#向開發(fā)人員隱藏了大部分基本內(nèi)存管理操作,因?yàn)樗褂昧死厥掌骱鸵?但是,有時(shí)候我們也需要直接訪問(wèn)內(nèi)存,例如:進(jìn)行平臺(tái)調(diào)用,性能優(yōu)化等等,本文給大家介紹了在C#中使用指針的示例代碼,需要的朋友可以參考下
    2024-10-10
  • 在C#中使用Channels的完整教程

    在C#中使用Channels的完整教程

    這篇文章主要介紹了在C#中使用Channels的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-03-03
  • Unity實(shí)現(xiàn)全屏截圖以及QQ截圖

    Unity實(shí)現(xiàn)全屏截圖以及QQ截圖

    這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)全屏截圖以及QQ截圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-04-04
  • C#的String和StringBuilder詳解

    C#的String和StringBuilder詳解

    這篇文章主要介紹了C#的String和StringBuilder詳解,本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-07-07
  • C#編寫Windows服務(wù)程序詳細(xì)步驟詳解(圖文)

    C#編寫Windows服務(wù)程序詳細(xì)步驟詳解(圖文)

    本文介紹了如何用C#創(chuàng)建、安裝、啟動(dòng)、監(jiān)控、卸載簡(jiǎn)單的Windows Service 的內(nèi)容步驟和注意事項(xiàng),需要的朋友可以參考下
    2017-09-09
  • C#排序算法之歸并排序

    C#排序算法之歸并排序

    這篇文章主要為大家詳細(xì)介紹了C#排序算法之歸并排序,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-01-01
  • C# 進(jìn)行圖片壓縮的示例代碼(對(duì)jpg壓縮效果最好)

    C# 進(jìn)行圖片壓縮的示例代碼(對(duì)jpg壓縮效果最好)

    這篇文章主要介紹了C# 進(jìn)行圖片壓縮的示例代碼,幫助大家更好的利用c# 處理圖片,提高辦公效率,感興趣的朋友可以了解下
    2020-11-11
  • C#條件拼接Expression<Func<T, bool>>的使用

    C#條件拼接Expression<Func<T, bool>>的使用

    本文主要介紹了C#條件拼接Expression<Func<T, bool>>的使用,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-02-02

最新評(píng)論

白水县| 乌鲁木齐市| 维西| 濉溪县| 紫金县| 吉安县| 太湖县| 虞城县| 安庆市| 都安| 雅安市| 江源县| 巴南区| 黑龙江省| 天等县| 蛟河市| 彭山县| 奈曼旗| 老河口市| 贺州市| 邯郸县| 肥城市| 镇安县| 阳泉市| 枣强县| 台湾省| 朝阳县| 东明县| 遂宁市| 门头沟区| 莱州市| 巴中市| 蕲春县| 荥经县| 罗山县| 漳浦县| 金平| 崇左市| 行唐县| 彩票| 天等县|