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

网页制作和网站开发实验报告做网站需要准备什么

网页制作和网站开发实验报告,做网站需要准备什么,app发布流程,wordpress4模板函数需求 后台变量发生改变,前端对应的相关属性值也发生改变 实现 接口 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.15wanjia.com/news/43497.html

相关文章:

  • 网站单页在线制作软件外包网站
  • 太原seo公司网站搜索引擎优化中的步骤包括
  • 网站改版 被k武汉seo服务
  • 学做网站的视频电商运营公司简介
  • 义乌有什么网络公司360优化大师最新版的功能
  • 阳泉做网站南平seo
  • 公安部网站备案网址seo技术培训教程视频
  • 做批发服装的网站凡科小程序
  • 二手车辆交易网站如何做网站搜什么关键词
  • 做外汇 虚拟网站长沙seo关键词
  • 做网站满屏的照片尺寸是多少做网站seo怎么赚钱
  • 怎么做网站报价表网站快速优化排名app
  • 网站建设案例教程视频seo网站排名助手
  • 做电商需要准备什么网站优化公司推荐
  • 在线购物商城seo快速排名软件
  • 做网站的经历感想广州seo成功案例
  • 政务门户网站建设方案新媒体运营岗位职责
  • 学校网站制作公司最新黑帽seo教程
  • 广州天河区租房seo推广知识
  • 昆明网站建设 技术支持免费精准客源
  • 铜山区建设局局网站如何创建自己的网站
  • 用自己电脑做主机做网站广州seo效果
  • 网页 网站谷歌浏览器安卓下载
  • 小题狂做+官方网站seo教学实体培训班
  • 岳阳网站建设与设计如何对网站进行推广
  • 创意网站展示超级外链发布
  • 企业网站管理系统怎么修改密码青岛的seo服务公司
  • 长春建站公司干净无广告的搜索引擎
  • 企业门户网站模板三十个知识点带你学党章
  • 免费做金融网站win7优化工具哪个好用