zoukankan      html  css  js  c++  java
  • Deriving from BindableBase更简单的绑定通知 GIS

    Visual Studio creates a BindableBase class in the Common folder of your projects. (Don’t confuse this class with the BindingBase class from which Binding derives.)

    BindableBase 是像下面这样定义的

    public abstract class BindableBase : INotifyPropertyChanged

    { public event PropertyChangedEventHandler PropertyChanged;

    protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName] String propertyName = null)
    { if (object.Equals(storage, value))

    return false; storage = value; this.OnPropertyChanged(propertyName); return true; }

    protected void OnPropertyChanged([CallerMemberName] string propertyName = null)

    { var eventHandler = this.PropertyChanged;

    if (eventHandler != null)

    { eventHandler(this, new PropertyChangedEventArgs(propertyName)); } } }

    BindableBase 类的使用方法:

    using Windows.UI; using ColorScrollWithDataContext.Common; namespace ColorScrollWithDataContext {
     public class RgbViewModel : BindableBase 
    { double red, green, blue;
     Color color = Color.FromArgb(255, 0, 0, 0);
     public double Red
    { 
    set
     { if (SetProperty<double>(ref red, value)) Calculate(); }
     get { return red; } } 
    public double Green { set { if (SetProperty<double>(ref green, value)) Calculate(); } get { return green; } }
     public double Blue { set { if (SetProperty<double>(ref blue, value)) Calculate(); } get { return blue; } }
     public Color Color { set { if (SetProperty<Color>(ref color, value)) { this.Red = value.R; this.Green = value.G; this.Blue = value.B; } } get { return color; } } 
    void Calculate() { this.Color = Color.FromArgb(255, (byte)this.Red, (byte)this.Green, (byte)this.Blue); }
     } 
    }

    使用方法 ,定义字段 double red,在 Red里面 属性set 调用

    SetProperty<double>(refred, value),就可以了
    SetProperty<double>(ref red, value)返回true 表示red 改变,返回false 没有改变

    。NET 4.5 。C# 5.0 这样用
  • 相关阅读:
    【转】ORACLE日期时间 等函数大全
    list_car()函数小记
    git代码提交流程
    windows连接ubuntu服务器方式
    win10专业版安装docker实战
    selenium来识别数字验证码
    web服务器、WSGI跟Flask(等框架)之间的关系
    pymysql的使用
    sql常用 语句总结
    sql语句insert into where 错误解析
  • 原文地址:https://www.cnblogs.com/gisbeginner/p/2670452.html
Copyright © 2011-2022 走看看