wp中的双向绑定
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace WpfApplication2
{
/// <summary>
/// 继承INotifyPropertyChanged接口,当值发生改变时,向客户端发出通知。
/// </summary>
public class SliderClass : INotifyPropertyChanged
{ public event PropertyChangedEventHandler PropertyChanged; public void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
} private double _length=0.0;
public double Length
{
get
{
return _length;
}
set
{
_length = value;
NotifyPropertyChanged("Length");
}
}
}
}
在mainpage中定义两个Slider。
<Grid x:Name="grid">
<Grid.RowDefinitions>
<RowDefinition Height="120*"/>
<RowDefinition Height="199*"/>
</Grid.RowDefinitions>
<Slider Value="{Binding Path=Length,Mode=TwoWay}" Margin="10,0,-10,71"/>
<Slider Value="{Binding Path=Length,Mode=TwoWay}" Grid.Row="" Margin="0,47,0,123"></Slider>
</Grid>
在后台new一个SliderClass作为Grid的数据源。会发现第一个Slider会带动第二个Slider变化,反之也成立。
本文主要理解INotifyPropertyChanged接口和实现双向绑定基础以及如何调用NotifyPropertyChanged。
wp中的双向绑定的更多相关文章
- AngularJS中数据双向绑定(two-way data-binding)
1.切换工作目录 git checkout step-4 #切换分支,切换到第4步 npm start #启动项目 2.代码 app/index.html Search: <input ng-m ...
- React中的“双向绑定”
概述 React并不是一个MVVM框架,其实它连一个框架都算不上,它只是一个库,但是react生态系统中的flux却是一个MVVM框架,所以我研究了一下flux官方实现中的"双向绑定&quo ...
- vue中数据双向绑定注意点
最近一个vue和element的项目中遇到了一个问题: 动态生成的对象进行双向绑定是失败 直接贴代码: <el-form :model="addClass" :rules=& ...
- vue中数据双向绑定的实现原理
vue中最常见的属v-model这个数据双向绑定了,很好奇它是如何实现的呢?尝试着用原生的JS去实现一下. 首先大致学习了解下Object.defineProperty()这个东东吧! * Objec ...
- javascript中的双向绑定
阅读目录 一:发布订阅模式实现数据双向绑定 二:使用Object.defineProperty 来实现简单的双向绑定. 前言: 双向数据绑定的含义:可以将对象的属性绑定到UI,具体的说,我们有一个对象 ...
- vue中的双向绑定
概述 今天对双向绑定感兴趣了,于是去查了下相关文章,发现有用脏检查的(angular.js),有用发布者-订阅者模式的(JQuery),也有用Object.defineProperty的(vue),其 ...
- 利用JS实现vue中的双向绑定
Vue 已经是主流框架了 它的好处也不用多说,都已经是大家公认的了 那我们就来理解一下Vue的单向数据绑定和双向数据绑定 然后再使用JS来实现Vue的双向数据绑定 单向数据绑定 指的是我们先把模板写好 ...
- AngularJS学习--- AngularJS中数据双向绑定(two-way data-binding) orderBy step4
1.切换工作目录 git checkout step- #切换分支,切换到第4步 npm start #启动项目 2.代码 app/index.html Search: <input ng-mo ...
- DelphiXe5中的双向绑定(使用使用TBindScope和TBindExpression,并覆盖AfterConstruction函数)
在Delphi下等这一功能很久了,虽然C#下早已实现了这一功能.但是在Dephi下尝试这项功能时还是有些许的激动.闲言少絮,直接上代码. unit BindingDemo; interface use ...
随机推荐
- Android蓝牙A2DP连接实现
代码地址如下:http://www.demodashi.com/demo/14624.html 开发环境: 开发工具:Androidstudio 适配机型:honor8(Android6.0), 坚果 ...
- PHP扩展的基本结构
1.下载php源码 git clone https://github.com/php/php-src.git 2,创建扩展 cd php-src/ext/ ./ext_skel --extname= ...
- HDUOJ-----(1329)Calling Extraterrestrial Intelligence Again
Calling Extraterrestrial Intelligence Again Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
- 【LeetCode】114. Distinct Subsequences
Distinct Subsequences Given a string S and a string T, count the number of distinct subsequences of ...
- POJ 3233 Matrix Power Series (矩阵乘法)
Matrix Power Series Time Limit: 3000MS Memory Limit: 131072K Total Submissions: 11954 Accepted: ...
- C# 默认参数/可选参数需要注意
在使用C#的默认参数/可选参数的时候,需要注意,参数的默认值是在编译的时候,自动加入调用方的. 如我有这样一个方法: public class Name { public void Test(Bool ...
- Android IPC机制(三)在Android Studio中使用AIDL实现跨进程方法调用
在上一篇文章Android IPC机制(二)用Messenger进行进程间通信中我们介绍了使用Messenger来进行进程间通信的方法.可是我们能发现Messenger是以串行的方式来处理client ...
- spring中AOP
1 AOP 的功能是把横切的问题(如性能监视.事务管理)模块化.AOP的核心是连接点模型,他提供在哪里发生横切. Spring AOP 的底层是通过使用 JDK 或 CGLib 动态代理技术为目标 b ...
- Install Ambari 2.2.0 from Public Repositories(Hadoop)
Step1: Download the Ambari repository on the Ambari Server host For Redhat/CentOS/Oracle: cd /etc/ ...
- 【转】js frame 框架编程
源地址:http://www.blogjava.net/lusm/archive/2008/02/11/179620.html 1 框架编程概述 一个Html 页面可以有一个或多个子框架,这些子框架以 ...