• 所有的重载设置字段作为参数传递到指定的值,而属性提高INotifyPropertyChanged.PropertyChanged事件。

  • 如果一个字段已经成功地改变,setProperty方法中返回。一些重载也需要一个回调方法作为参数。调用该回调后场已经改变。

  • 手动设置一个基本的私有字段,然后调用的BindableBase.RaisePropertyChanged方法重载之一。

    所有RaisePropertyChanged方法重载需要作为输入参数,这些属性提高INotifyPropertyChanged.PropertyChanged事件。

using System;
using System.Collections.Generic;
using System.Linq;
using DevExpress.Xpf.Mvvm; public class BindableObject : BindableBase { //The property's setter below uses the SetProperty method, which does the following:
//1. Changes the underlying private field.
//2. Raises a change notification for the property, whose name is retrieved from the expression: () => StringProperty.
//This is the preferable method for setting a property in most cases, because it provides strong typing.
//The method is slightly slower than passing the property name as a string (see the declaration of StringProperty2).
string stringProperty;
public string StringProperty {
get { return stringProperty; }
set { SetProperty(ref stringProperty, value, () => StringProperty); }
} //The property's setter below uses the SetProperty method, which does the following:
//1. Changes the underlying private field.
//2. Raises a change notification for the property with the specified name.
//This method is slightly faster than the previous variant, but does not provide strong typing.
string stringProperty2;
public string StringProperty2 {
get { return stringProperty2; }
set { SetProperty(ref stringProperty2, value, "StringProperty2"); }
} //The property's setter below uses the SetProperty method, which does the following:
//1. Changes the underlying private field.
//2. Invokes your callback method (OnStringProperty3Changed) if the property has been changed.
//3. Raises a change notification for the property, whose name is retrieved from the expression: () => StringProperty3.
string stringProperty3;
public string StringProperty3 {
get { return stringProperty3; }
set {
SetProperty(ref stringProperty3, value, () => StringProperty3, OnStringProperty3Changed);
//An alternative form:
SetProperty(ref stringProperty3, value, () => StringProperty3, () => OnStringProperty3Changed());
}
}
private void OnStringProperty3Changed() {
} //The property's setter below uses the SetProperty method, which does the following:
//1. Changes the underlying private field.
//2. Raises a change notification for the property, whose name is retrieved from the expression: () => StringProperty4.
//You can write additional code within the "if" statement, which will be executed after the property has changed.
string stringProperty4;
public string StringProperty4 {
get { return stringProperty4; }
set {
if (SetProperty(ref stringProperty4, value, () => StringProperty4)) {
//The SetProperty method returns true if the property has been changed.
///Do “something” after the property has changed.
//...
}
}
} //The following property's setter does the following:
//1. Changes the underlying private field.
//2. Raises a change notification via the RaisePropertyChanged method.
string stringProperty5;
public string StringProperty5 {
get { return stringProperty5; }
set {
if (stringProperty5 == value)
return;
stringProperty5 = value;
RaisePropertyChanged("StringProperty5");
//An alternative form using a lambda expression, which provides strong typing:
RaisePropertyChanged(() => StringProperty5);
//Do “something” after the property has changed.
//...
}
} //The following property's setter changes a property, and raises change notifications for this property and its dependent properties:
//1. Changes the underlying private field (stringProperty6).
//2. Raises change notifications for StringProperty and StringProperty2.
//3. Raises a change notification for StringProperty6.
//This is the preferable variant in most cases, because it features strong typing.
//The method is slightly slower than passing the property name as a string (see the implementation of StringProperty7).
string stringProperty6;
public string StringProperty6 {
get { return stringProperty6; }
set {
SetProperty(ref stringProperty6, value, () => StringProperty6, () => RaisePropertiesChanged(() => StringProperty, () => StringProperty2)); //An alternative form that is easier to read:
if (SetProperty(ref stringProperty6, value, () => StringProperty6)) {
RaisePropertiesChanged(() => StringProperty, () => StringProperty2);
}
}
} //The following property's setter changes the property and raises change notifications for this property and its dependent properties:
//1. Changes the underlying private field (stringProperty7).
//2. Raises a change notification for StringProperty7.
//3. Raises change notifications for StringProperty and StringProperty2.
//This is a quicker alternative to the previous example, but does not provide strong typing.
string stringProperty7;
public string StringProperty7 {
get { return stringProperty7; }
set {
if (SetProperty(ref stringProperty7, value, () => StringProperty7)) {
RaisePropertiesChanged("StringProperty", "StringProperty2");
}
}
}
}

该代码来自官网

Devexpress RaisePropertyChanged的更多相关文章

  1. Xamarin devexpress Grid

    Devexpress 提供了datagrid 控件对于xamarin 进行支持.整个世界美好了,已经无法用语言来形容一个 被列表控件折磨的要死的人看到熟悉的图标时候的激动了.还有一点引用官网的原话: ...

  2. Devexpress Winform MVVM

    归纳总结备忘 Devexpress Winform MVVM Practice 前言 MVVM Devexpress 正文 databindings及 UI Triggers Command 委托Co ...

  3. DevExpress MVVM<1>

    DevExpress MVVM 概念 模型 -定义数据和您的业务逻辑. 视图 -指定UI,包括绑定到ViewModel中的属性和命令的所有可视元素(按钮,标签,编辑器等). ViewModel-连接模 ...

  4. 在DevExpress程序中使用GridView直接录入数据的时候,增加列表选择的功能

    在我上篇随笔<在DevExpress程序中使用Winform分页控件直接录入数据并保存>中介绍了在GridView以及在其封装的分页控件上做数据的直接录入的处理,介绍情况下数据的保存和校验 ...

  5. DevExpress - 使用 GaugeControl 标尺组件制作抽奖程序 附源码

    前不久,公司举办了15周年庆,其中添加了一个抽奖环节,要从在读学员中随机抽取幸运学员,当然,这个任务就分到了我这里. 最后的效果如下,启动有个欢迎页面,数据是来自Excel的,点击开始则上面的学号及姓 ...

  6. 图解DevExpress RichEditControl富文本的使用,附源码及官方API

    9点半了,刚写到1.2.   该回家了,明天继续写完. 大家还需要什么操作,留言说一下,没有的我明天继续加. 好久没有玩DevExpress了,今天下载了一个玩玩,发现竟然更新到14.2.5了..我去 ...

  7. DevExpress学习系列(控件篇):GridControl的基本应用

    一般属性设置 不显示分组框:Gridview->Option View->Show Group Panel=false 单元格不可编辑:gridcontrol -->gridview ...

  8. 在DevExpress程序中使用Winform分页控件直接录入数据并保存

    一般情况下,我们都倾向于使用一个组织比较好的独立界面来录入或者展示相关的数据,这样处理比较规范,也方便显示比较复杂的数据.不过在一些情况下,我们也可能需要直接在GridView表格上直接录入或者修改数 ...

  9. 在DevExpress程序中使用TeeList控件以及节点查询的处理

    在很多情况下,我们需要通过树列表进行数据的展示,如一些有层次关系的数据,通过有层级的展示,能够使用户更加直观查看和管理相关的数据.在一般Winform开发的情况下,可以使用微软的TreeView控件, ...

随机推荐

  1. 用"hosting.json"配置ASP.NET Core站点的Hosting环境

    通常我们在 Prgram.cs 中使用硬编码的方式配置 ASP.NET Core 站点的 Hosting 环境,最常用的就是 .UseUrls() . public class Program { p ...

  2. ReactJS入门(四)—— 组件API

    本篇将介绍 React 组件的API,其中主要的几个API我们在第一篇的时候便已介绍过,这里可以做个温故知新. 本篇的代码你也可以在我的Github上获取到. setState 参数: nextSta ...

  3. JS原型继承和类式继承

    前言 一个多月前,卤煮读了一篇翻译过来的外国人写的技术博客.此君在博客中将js中的类(构造)继承和原型继承做了一些比较,并且得出了结论:建议诸位在开发是用原型继承.文中提到了各种原型继承的优点,详细的 ...

  4. 史上最牛js

    js的功能有多强大,能做到多极致?当然前提是能用,不要搞到需要超级计算器才能运行,那不算. 今天一朋友给我介绍了这个:http://bellard.org/jslinux/ 倒腾了半天后,我只能这么感 ...

  5. 东哥读书小记 之 《MacTalk人生元编程》

         一直以来的自我感觉:自己是个记性偏弱的人.反正从小读书就喜欢做笔记(可自己的字写得巨丑无比,尼玛不科学呀),抄书这事儿真的就常发生俺的身上. 因为那时经常要背诵课文之类,反正为了怕自己忘记, ...

  6. Java ServletContextListener用法

    ServletContext 被 Servlet 程序用来与 Web 容器通信.例如写日志,转发请求.每一个 Web 应用程序含有一个Context,被Web应用内的各个程序共享.因为Context可 ...

  7. WinRAR 4.20 beta2 key!注册文件 注册码

    WinRAR 4.20 beta2 key!注册文件 注册码 WinRAR 4.20 beta2注册文件 WinRAR 4.20 beta2 working key ================= ...

  8. MongoDB 聚合操作

    在MongoDB中,有两种方式计算聚合:Pipeline 和 MapReduce.Pipeline查询速度快于MapReduce,但是MapReduce的强大之处在于能够在多台Server上并行执行复 ...

  9. Trace Flag

    Trace Flag能够影响Sql Server的行为,主要用于diagnose performance issue,官方解释是: Trace flags are used to temporaril ...

  10. EntityFramework之孩子删除(四)(你以为你真的懂了?)

    前言 从表面去看待事物视线总有点被层层薄雾笼罩的感觉,当你静下心来思考并让指尖飞梭于键盘之上,终将会拨开浓雾见青天.这是我切身体验. 在EF关系配置中,我暂且将主体对象称作为父亲,而依赖对象称作为孩子 ...