popular databinding expressions

本文详细解析了WPF中的数据绑定表达式,包括DataContextBindings、RelativeSourceBinding和CurrentItemofCollectionBindings等核心概念,帮助开发者更高效地进行数据绑定操作。

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

Popular DataBinding Expressions

DataContext Bindings

Each control in WPF has a DataContext property. It's meant to be bound to an object that contains the data to be displayed. The DataContext property is inherited along the logical tree.

{Binding}
Binds object in the DataContext
{Binding Name}
Binds the Name property of the object in the DataContext
{Binding Name.Length}
Binds the Length property of the Name property of the object in the DataContext.

RelativeSource Binding

The relative source mode of the binding extension helps you to bind to an object with an relative relation to you. You don't know your or its abolute position, but you know if it's the previous or next item, two levels above you or of an specific type.

{Binding RelativeSource={RelativeSource Self}}
Bind to your self. Helpful to access your own properties.
{Binding Text, RelativeSource={RelativeSource Self}}
Binds Text property of the target element.
{Binding IsSelected, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}}}
Binds to the IsSelected property of a parent element of type ListBoxItem.

Current Item of Collection Bindings

The slash is a special operator that lets you access the current item of a collection view.

{Binding /}
Binds to the current item of a collection in the data context.
{Binding Customers/}
Binds to the current item of a collection from the Customer property within the data context.
{Binding Customers/Name}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值