#106 – Set Property Value to Point to Another Object(设置属性值指向另一个object)

原文地址:https://wpf.2000things.com/2010/10/26/106-set-property-value-to-point-to-another-object/

有时候在XAML中需要设置当前元素某个属性指向另外一个元素。

比如CommandTarget 属性,它被用来判断当前控件是否是command的发起者。

举个例子,你有一个用来执行拷贝命令的Button ,你希望内容可以拷贝到一个TextBox中,那么你就得设置Button的CommandTarget 属性指向这个TextBox

在XAML中通过Binding 拓展标签来实现,通过设置绑定的ElementName 属性去指向期望的控件。

<Button Content="Paste" Command="ApplicationCommands.Paste"
    CommandTarget="{Binding ElementName=myTextBox}" />
<TextBox Name="myTextBox"/>

XAML2009允许使用x:Reference 拓展标签来实现这个,但是在WPF的XAML中不支持。

<Button Content="Paste" Command="ApplicationCommands.Paste"
    CommandTarget="{x:Reference myTextBox}" />
<TextBox Name="myTextBox"/>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值