Dependency properties overview

Custom dependency properties

Attached properties overview

Custom attached properties

Quickstart: Data binding to controls

Data binding overview (XAML)

使用代码创建绑定

你还可以使用规程代码而不是 XAML 来将 UI 元素连接到数据。若要执行此操作,先创建新 Binding 对象,设置适当的属性,然后调用 FrameworkElement.SetBindingBindingOperations.SetBinding。如果你希望在运行时选择绑定属性值或在多个控件中共享单个绑定,以编程方式创建绑定十分有用。但是请注意,调用 SetBinding 后,无法更改绑定属性值。

以下示例演示了如何使用代码实现之前的绑定。

// Create an instance of the MyColors class
// that implements INotifyPropertyChanged.
MyColors textcolor = new MyColors(); // Brush1 is set to be a SolidColorBrush with the value Red.
textcolor.Brush1 = new SolidColorBrush(Colors.Red); // Set the DataContext of the TextBox MyTextBox.
MyTextBox.DataContext = textcolor; // Create the binding and associate it with the text box.
Binding binding = new Binding() { Path = new PropertyPath("Brush1") };
MyTextBox.SetBinding(TextBox.ForegroundProperty, binding);

以增量方式加载数据

你可以使用增量加载将列表控件绑定到任意的大型数据源,且仍获得高性能。例如,你可以将列表控件绑定到必应图像查询结果,而无需一次性加载所有结果。你只需立即加载部分结果,再根据需要加载其他结果。 为支持增量加载,你必须在支持集合更改通知的数据源上实现 ISupportIncrementalLoading。当数据绑定引擎请求更多数据时,你的数据源必须发出相应的请求、集成结果,然后发送相应的通知以更新 UI。有关详细信息,请参阅 XAML 数据绑定示例

How to bind to hierarchical data and create a master/details view (XAML)

Quickstart: Reading and writing files

Quickstart: Accessing files with file pickers

How to continue your Windows Phone app after calling a file picker

UWP深入学习三:依赖属性、附加属性和数据绑定的更多相关文章

  1. 重新想象 Windows 8 Store Apps (16) - 控件基础: 依赖属性, 附加属性, 控件的继承关系, 路由事件和命中测试

    原文:重新想象 Windows 8 Store Apps (16) - 控件基础: 依赖属性, 附加属性, 控件的继承关系, 路由事件和命中测试 [源码下载] 重新想象 Windows 8 Store ...

  2. 背水一战 Windows 10 (78) - 自定义控件: 基础知识, 依赖属性, 附加属性

    [源码下载] 背水一战 Windows 10 (78) - 自定义控件: 基础知识, 依赖属性, 附加属性 作者:webabcd 介绍背水一战 Windows 10 之 控件(自定义控件) 自定义控件 ...

  3. WPF学习笔记——依赖属性(Dependency Property)

    1.什么是依赖属性 依赖属性是一种可以自己没有值,并且通过Binding从数据源获得值(依赖在别人身上)的属性,拥有依赖属性的对象被称为"依赖对象". 依赖项属性通过调用 Regi ...

  4. WPF 依赖属性&附加属性

    依赖属性 暂无 附加属性 1.在没有控件源码的前提下增加控件的属性 2.多个控件需要用到同一种属性 使用附加属性可以减少代码量,不必为每一个控件都增加依赖属性 3.属性不确定是否需要使用 在某些上下文 ...

  5. XAML实例教程系列 - 依赖属性和附加属性(四)

    XAML实例教程系列 - 依赖属性和附加属性 2012-06-07 13:11 by jv9, 1479 阅读, 5 评论, 收藏, 编辑 微软发布Visual Studio 2012 RC和Wind ...

  6. WPF入门教程系列十三——依赖属性(三)

    四. 只读依赖属性 在以前在对于非WPF的功能来说,对于类的属性的封装中,经常会对那些希望暴露给外界只读操作的字段封装成只读属性,同样在WPF中也提供了只读属性的概念,如一些 WPF控件的依赖属性是只 ...

  7. WPF 自定义依赖属性

      原博客地址:http://www.cnblogs.com/DebugLZQ/archive/2012/11/30/2796021.html    DependencyObject和Dependen ...

  8. [UWP]为附加属性和依赖属性自定义代码段(兼容UWP和WPF)

    1. 前言 之前介绍过依赖属性和附加属性的代码段,这两个代码段我用了很多年,一直都帮了我很多.不过这两个代码段我也多年没修改过,Resharper老是提示我生成的代码可以修改,它这么有诚意,这次就只好 ...

  9. wpf依赖属性、绑定实现原理、附加属性学习

    依赖属性和普通属性相比节省内存的原因:对于普通属性,每个对象有需要存储一个普通属性的值,即便是默认值.而依赖属性的默认值是静态的存储在类中的,所有对象都使用同一默认值,所以对于拥有大量属性的控件来说这 ...

随机推荐

  1. poj 2513 Colored Sticks trie树+欧拉图+并查集

    点击打开链接 Colored Sticks Time Limit: 5000MS   Memory Limit: 128000K Total Submissions: 27955   Accepted ...

  2. impala简单使用

    impala-shell connect ha1:21000 更新元信息 invalidate metadata;

  3. 57. Jump Game && Jump Game II

    Jump Game Given an array of non-negative integers, you are initially positioned at the first index o ...

  4. HDFS--(HA)初始化与启动

    1.启动zk 2.启动journalnode:         hadoop-daemons.sh start journalnode 3.格式化zkfc--让在zookeeper中生成ha节点    ...

  5. LINQ inner join

    用的EF,需要联合查询,否则就需要反复的访问数据库 var query = from fp in db.Form_ProcessSets                         join n  ...

  6. /etc/resolv.conf overwritten. Redhat/Centos

    Prevent /etc/resolv.conf from being blown away by RHEL/CentOS after customizing If you are using RHE ...

  7. AngularJs 简单实现全选,多选操作

    很多时候我们在处理CURD(增删改查)的时候需要实现批量操作数据,这时候就必须使用多选操作. Angular 中实现如下(当然还有很多种比笔者写的更好的方法,这里只是简单的实现.) demo 演示地址 ...

  8. php 向asmx发送请求 || php 发送xml请求, 以及处理返回的xml结果

    var $live_url = 'https://processing.ukash.com/RPPGateway/process.asmx'; $source = array( 'SecurityTo ...

  9. MessageFormat不支持{

    转自 :http://zqc-0101.iteye.com/blog/1140140 MessageFormat用来格式化一个消息,通常是一个字符串,比如: String str = "I' ...

  10. mysql的时间转化

    1.1 获得当前日期+时间(date + time)函数:now() 除了 now() 函数能获得当前的日期时间外,MySQL 中还有下面的函数: current_timestamp()   curr ...