windows8商店应用程序开发数据绑定

本文深入探讨了WPF中数据绑定的基本概念,包括Binding、StaticResource、TemplateBinding和RelativeSource,并详细解释了它们的应用场景和区别。同时介绍了如何在WPF中灵活使用这些特性来实现高效的数据展示和交互。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. Binding
<targetObject targetProperty="{Binding}" ...> ... </targetObject>

 <targetObject targetProperty="{Binding [Path=]bindingSourceProperty}" ...> ... </
targetObject>


2. StaticResource
<object propertyName="{StaticResource resourceKey}" ...> ... </ object>
 resourceKey 是被引用的资源的键,由资源定义时的 x:Key 或 x:Name 指定


3. TemplateBinding
 <templateObject templateProperty="{TemplateBinding [Property=] sourceObjectProperty}" 
...> ... </templateObject>


templateObject 是 模 板 对 象 ;templateProperty 是 模 板 对 象 的 属 性 ;Property
是 TemplateBinding 的 属 性, 用 于 指 定 被 绑 定 对 象 的 属 性, 通 常 可 省 略 不 写 ;
sourceObjectProperty 是被绑定对象的属性。


4. RelativeSource
 TemplatedParent 模式通常使用于 ControlTemplate 元素定义中
 <object property="{Binding RelativeSource={RelativeSource [Mode=]modeValue}}" ...> 
... </object>

 <object property="{Binding RelativeSource={RelativeSource [Mode=]
modeValue},[Path=]bindedProperty}" ...> ... </object>
Mode 是 RelativeSource 的属性,用于设置绑定模式,属性值有 Self
和 TemplatedParent。当 Mode 属性取值为 Self 时,表示元素或元素的属性是绑定源;取值为
TemplatedParent 时,表示引用 ControlTemplate 模板的元素或元素的属性是绑定源。Path 也
是 RelativeSource 的属性,用于指定被绑定的属性
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值