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

萍乡企业做网站哈尔滨百度推广公司

萍乡企业做网站,哈尔滨百度推广公司,免费做外贸的网站,挂机宝怎么做网站需求 后台变量发生改变,前端对应的相关属性值也发生改变 实现 接口 INotifyPropertyChanged 用于通知客户端(通常绑定客户端)属性值已更改。 示例 示例一 官方示例代码如下 using System; using System.Collections.Generic; using System.ComponentModel; using Sys…

需求

后台变量发生改变,前端对应的相关属性值也发生改变

实现

接口 INotifyPropertyChanged 用于通知客户端(通常绑定客户端)属性值已更改。

示例

示例一

官方示例代码如下

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//将下面的命名空间更改为项目的名称
//或者在创建项目时使用以下名称命名项目。
namespace TestNotifyPropertyChangedCS
{//这个表单演示了如何使用BindingSource来绑定//一个列表到DataGridView控件。这个列表没有//引发更改通知。然而,DemoCustomer类型//在列表中。  public partial class Form1 : Form{//此按钮可更改列表元素的值。 private Button changeItemBtn = new Button();// 这个DataGridView控件显示列表的内容。private DataGridView customersDataGridView = new DataGridView();// 这个BindingSource将列表绑定到DataGridView控件。private BindingSource customersBindingSource = new BindingSource();public Form1(){InitializeComponent();// 设置“更改项目”按钮。this.changeItemBtn.Text = "Change Item";this.changeItemBtn.Dock = DockStyle.Bottom;this.changeItemBtn.Click +=new EventHandler(changeItemBtn_Click);this.Controls.Add(this.changeItemBtn);//设置DataGridView。  customersDataGridView.Dock = DockStyle.Top;this.Controls.Add(customersDataGridView);this.Size = new Size(400, 200);}private void Form1_Load(object sender, EventArgs e){//创建并填充DemoCustomer对象列表//它将向DataGridView提供数据。 BindingList<DemoCustomer> customerList = new BindingList<DemoCustomer>();customerList.Add(DemoCustomer.CreateNewCustomer());customerList.Add(DemoCustomer.CreateNewCustomer());customerList.Add(DemoCustomer.CreateNewCustomer());// 将列表绑定到BindingSource。  this.customersBindingSource.DataSource = customerList;// 将BindingSource附加到DataGridView。this.customersDataGridView.DataSource =this.customersBindingSource;}//修改CompanyName属性的值//当点击“更改项目”按钮时,列表中的项目。  void changeItemBtn_Click(object sender, EventArgs e){//从BindingSource获取对列表的引用。 BindingList<DemoCustomer> customerList =this.customersBindingSource.DataSource as BindingList<DemoCustomer>;//修改CompanyName属性的值//列表中的第一项。  customerList[0].CustomerName = "Tailspin Toys";customerList[0].PhoneNumber = "(708)555-0150";}}//这是一个简单的客户类//实现IPropertyChange接口。public class DemoCustomer : INotifyPropertyChanged{//这些字段保存公共属性的值。  //Guid.NewGuid();随机生成唯一标识符,一般在项目中用来生成数据库的主键Id。private Guid idValue = Guid.NewGuid();private string customerNameValue = String.Empty;private string phoneNumberValue = String.Empty;public event PropertyChangedEventHandler PropertyChanged;//该方法由每个属性的Set访问器调用。//应用于可选propertyName的CallerMemberName属性//参数导致调用方的属性名被替换为参数。private void NotifyPropertyChanged([CallerMemberName] String propertyName = ""){PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));}//构造函数是私有的,用来强制工厂模式。  private DemoCustomer(){customerNameValue = "Customer";phoneNumberValue = "(312)555-0100";}//这是一个公共工厂方法。public static DemoCustomer CreateNewCustomer(){return new DemoCustomer();}//该属性表示一个ID,合适//用作数据库中的主键。  public Guid ID{get{return this.idValue;}}public string CustomerName{get{return this.customerNameValue;}set{if (value != this.customerNameValue){this.customerNameValue = value;NotifyPropertyChanged();}}}public string PhoneNumber{get{return this.phoneNumberValue;}set{if (value != this.phoneNumberValue){this.phoneNumberValue = value;NotifyPropertyChanged();}}}}
}

示例演示

before

after

示例二

本示例提供了多种绑定方式,使用接口进行绑定,不使用接口进行绑定

1.在MainWindow中进行属性更改

2.在MainWindow中建立一个新的usercontrol查看是否可以进行相同的属性更改

3.原始示例中展示了Text的文字内容更改,尝试对DataTrigger的Binding使用同样的方法查看是否可以更改

后端代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml.Linq;namespace WpfApp1
{/// <summary>/// Interaction logic for MainWindow.xaml/// </summary>public partial class MainWindow : Window, INotifyPropertyChanged{public MainWindow(){this.DataContext = thi
http://www.hkea.cn/news/801857/

相关文章:

  • 国内开源代码网站搜了网推广效果怎么样
  • html5 metro风格网站模板今日新闻事件
  • 网站不在首页显示出来做网络推广
  • 上海网站seo公司网页推广平台
  • 网站服务器租用价格表百度怎么发布自己的广告
  • 经纪人做网站技巧搜索引擎入口yandex
  • 教育网站制作哪家服务好全球外贸采购网
  • 响应式网络网站源码百度关键词查询网站
  • 南京网站制作设计公司网络运营团队
  • 阿里巴巴上怎样做自己的网站seo网站优化网站编辑招聘
  • 网站做付费推广都需要问什么网络热词2022
  • 给男票做网站表白的软件产品市场推广计划书
  • 西安网站制作定制怎么制作自己的个人网站
  • wordpress 如何移动端盐城seo优化
  • asp.net 制作网站开发百度竞价排名软件
  • 百度爱采购推广平台天津网络推广seo
  • 福州市闽侯县建设局网站推广引流吸引人的文案
  • wordpress目录 读写权限泰安短视频seo
  • 东莞建设网站流程澎湃新闻
  • 萧县住房和城乡建设局网站seo排名推广工具
  • 企业网站php模板下载百度百科官网首页
  • 做愛視頻网站在线网页制作网站
  • 织梦pc怎么做手机网站搜索引擎优化的基础是什么
  • 课程建设网站设计源码爱站网反链查询
  • 安徽省建设业协会网站个人网页制作教程
  • 好的摄影网站推荐福州seo顾问
  • html做的好看的网站如何宣传推广产品
  • 微信手机网站制作怎么引流客源最好的方法
  • 宿州建设网站公司前端seo搜索引擎优化
  • 做王境泽表情的网站百度seo关键词优化排名