当前位置: 首页 > news >正文

做运营需要知道素材网站搜索引擎有哪些

做运营需要知道素材网站,搜索引擎有哪些,北京最新疫情公布,沧州做公司网页的公司有哪些文章目录 前言相关链接代码仓库项目配置代码初始代码ViewPersonViewModel 尝试老办法通知解决方案ObservableCollectionBindingListICollectionView 总结 前言 我们这次详细了解一下列表通知的底层是怎么实现的 相关链接 十月的寒流 MVVM实战技巧之:可被观测的集合…

文章目录

  • 前言
  • 相关链接
  • 代码仓库
  • 项目配置
  • 代码
    • 初始代码
      • View
      • Person
      • ViewModel
    • 尝试老办法通知
    • 解决方案
      • ObservableCollection
      • BindingList
      • ICollectionView
  • 总结

前言

我们这次详细了解一下列表通知的底层是怎么实现的

相关链接

十月的寒流

在这里插入图片描述
在这里插入图片描述

MVVM实战技巧之:可被观测的集合(ObservableCollection & BindingList)

代码仓库

我为了方便展示源代码,我将代码提交到了代码仓库里面

B站【十月的寒流】对应课程的代码 Github仓库

项目配置

如何使用我这里就不展开说明了

WPF CommunityToolkit.Mvvm

WPF CommunityToolkit.Mvvm Messenger通讯

在这里插入图片描述

WPF-UI HandyControl 简单介绍

WPF-UI HandyControl 控件简单实战+IconPacks矢量图导入

在这里插入图片描述

Bogus,.NET生成批量模拟数据
在这里插入图片描述

代码

初始代码

View

 <UserControl.DataContext><viewModels:DemoViewModel /></UserControl.DataContext><DockPanel><StackPanel DockPanel.Dock="Bottom"><Button Command="{Binding AddItemCommand}"Content="添加数据"></Button></StackPanel><DataGrid ItemsSource="{Binding People}"></DataGrid></DockPanel>

Person

public class Person
{public int Id { get; set; }public string FirstName { get; set; }public string LastName { get; set; }public string FullName { get; set; }public DateOnly BirthDay { get; set; }public static Person FakerOne => faker.Generate();public static IEnumerable<Person> FakerMany(int count)=>faker.Generate(count);private static readonly Faker<Person> faker = new Faker<Person>().RuleFor(t=>t.Id,f=>f.IndexFaker).RuleFor(t=>t.FirstName,f=>f.Name.FirstName()).RuleFor(t=>t.LastName,f=>f.Name.LastName()).RuleFor(t=>t.FullName,f=>f.Name.FullName()).RuleFor(t=>t.BirthDay,f=>f.Date.BetweenDateOnly(new DateOnly(1990,1,1),new DateOnly(2010,1,1)));
}

ViewModel

public partial class DemoViewModel:ObservableObject
{[ObservableProperty]private List<Models.Person> people = new List<Models.Person>();[RelayCommand]public void AddItem(){People.Add(Models.Person.FakerOne);}public DemoViewModel() {People = Models.Person.FakerMany(5).ToList();}}

现在的代码是没有实现通知,点击按钮也不会添加

在这里插入图片描述

尝试老办法通知

        public void AddItem(){People.Add(Models.Person.FakerOne);//没有效果//OnPropertyChanged(nameof(People));//没有效果//SetProperty(ref people, people);}

而且在我们点击ListBox的时候,会报错。这个就说明,其实List已经修改了,但是这个通知方法不行。原因是List指向的是一个地址空间,这个地址空间并没有变化。
在这里插入图片描述

解决方案

ObservableCollection

简单的解决方案就是改成ObservableCollection,这里就不展开说明了。
在这里插入图片描述
但是有一个问题,这个ObservableCollection只在Count更新的时候触发自动更新。里面的Person值修改的时候是不会触发更新的。

如果有联动更新的需求,可以直接在【CollectionChanged】添加对应的代码
在这里插入图片描述

BindingList

这里我就不展开说明了,直接上视频的源代码了。

在这里插入图片描述
在这里插入图片描述

ICollectionView

WPF 【十月的寒流】学习笔记(1):DataGrid过滤

更好的解决方案就是直接更新。我们直接刷新ItemSorce

<UserControl x:Class="WpfMvvmDemo.Views.DemoView"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:local="clr-namespace:WpfMvvmDemo.Views"xmlns:viewModels="clr-namespace:WpfMvvmDemo.ViewModels"mc:Ignorable="d"d:DesignHeight="450"d:DesignWidth="800"><UserControl.DataContext><viewModels:DemoViewModel /></UserControl.DataContext><DockPanel><StackPanel DockPanel.Dock="Bottom"HorizontalAlignment="Left"Orientation="Horizontal"><Button Command="{Binding AddItemCommand}"Margin="5"Content="添加数据"></Button><Button Command="{Binding UpIdCommand}"Margin="5"Content="增加Id"></Button></StackPanel><DataGrid ItemsSource="{Binding PeopleView}"></DataGrid></DockPanel>
</UserControl>
using Bogus;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;namespace WpfMvvmDemo.ViewModels
{public partial class DemoViewModel:ObservableObject{[ObservableProperty]private List<Models.Person> people = new List<Models.Person>();[ObservableProperty]private ICollectionView peopleView;[RelayCommand]public void AddItem(){People.Add(Models.Person.FakerOne);//没有效果//OnPropertyChanged(nameof(People));//没有效果//SetProperty(ref people, people);//直接更新整个视图源PeopleView.Refresh();}[RelayCommand]public void UpId(){foreach (var item in People){item.Id += 10;}PeopleView.Refresh();}public DemoViewModel() {People = Models.Person.FakerMany(5).ToList();PeopleView = CollectionViewSource.GetDefaultView(People);}}
}

为了方便,我们也可以直接新建一个类,这里就把代码放一下,就不展开说明了

    public class CollectionData<T> where T : class{public IEnumerable<T> Data { get; set; }public ICollectionView CollectionView { get; set; }public CollectionData() { }public void Init(){CollectionView = CollectionViewSource.GetDefaultView(Data);CollectionView.Refresh();}}

总结

我觉得当时【十月的寒流】那个视频一直在想用MVVM去通知更新,当然他的主题也是使用MVVM自动更新。但是ItemSorce随时都有可能发生修改。要么就是每次事件之后修改,要么就给每个可能会触发的属性添加通知。

http://www.ds6.com.cn/news/50222.html

相关文章:

  • 男医生给产妇做内检小说网站公众号怎么做文章推广
  • 怎么用图片做网站背景图世界杯最新排名
  • 怎样用网站做淘宝客新产品推广方案策划
  • 网站建设售后完善app开发多少钱
  • 科技有限公司 网站制作网站快速排名服务
  • cms做淘宝客网站东莞网站优化公司
  • 西数网站管理助手网络推广服务协议
  • 网站建设营销方案南平seo
  • 网站四对联广告代码广州seo搜索
  • 赣州市 城乡建设委员会网站个人怎么做互联网推广平台
  • 百度网站标题优化缅甸最新新闻
  • 沈阳外贸网站建设网站优化seo培训
  • mui做的h5网站案例企业网站制作教程
  • 汕头 网站商丘seo公司
  • 网站建设创新郑州网络营销公司排名
  • google map wordpress网站seo李守洪排名大师
  • 北京海大网智网站建设制作公司微信小程序开发费用
  • 如何给网站做防盗链网站推广软件下载
  • 建设工程信息网官网新网站免费网站alexa排名查询
  • 西安给大学做网站公司全媒体广告代理加盟
  • 毕设做网站可以用模板吗影响seo排名的因素
  • 四川建设局网站编程培训机构
  • 网站后台和前台不一致班级优化大师客服电话
  • 绵阳建设招投标在哪个网站营销策略4p分析怎么写
  • 高端网站建设创新seo优化评论
  • 网站开发人员工作内容东莞做网页建站公司
  • 公众号开发信息推推蛙seo
  • 网络服务合同交印花税吗seo关键词快速提升软件官网
  • 做网站要学什么专业什么是seo技术
  • 免费信息网站建设平台免费百度广告怎么投放