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 这样用
  • 相关阅读:
    HDU6470 ()矩阵快速幂
    O(1)乘法与快速乘O(log)
    imos 学习笔记五 抓拍 c#
    imos 学习笔记四 录像 c#
    imos 学习笔记三 下载指定时间段视频信息 c#
    imos学习笔记二 用户登录c#
    imos学习笔记一 sdk开发环境
    Hbase(nosql)体系结构有基本操作 笔记八
    zookeeper的安装与配置 笔记七
    mapReduce体系结构和各种算法 笔记六
  • 原文地址:https://www.cnblogs.com/gisbeginner/p/2670452.html
Copyright © 2011-2022 走看看