WPF 绑定到附加属性 绑定到只读属性
2012-07-25 10:04
489 查看
绑定有两个需要注意的地方
1.如果绑定到 附加属性(Binding Attached Property),需要加上括号,这个比较特别,例如
2.如果绑定到只读的属性(Binding to readonly property),例如IsFocused,需要加上 Mode = OneWay
1.如果绑定到 附加属性(Binding Attached Property),需要加上括号,这个比较特别,例如
<TextBox x:Name="tbUserName" Width="200" Grid.Column="0" Margin="10,10,0,0" Foreground="Gray" nasSetting:TextBoxMaskHelper.MaskText="Please input username" Text="{Binding Path=(nasSetting:TextBoxMaskHelper.MaskText),Mode=OneWay,ElementName=tbUserName}" Height="30" CharacterCasing="Normal">
<TextBox.Foreground> <MultiBinding Converter="{StaticResource MaskBrushConverter}"> <Binding Path="Text" ElementName="tbUserName" UpdateSourceTrigger="PropertyChanged"/> <Binding Path="(nasSetting:TextBoxMaskHelper.MaskText)" ElementName="tbUserName" /> </MultiBinding> </TextBox.Foreground>
2.如果绑定到只读的属性(Binding to readonly property),例如IsFocused,需要加上 Mode = OneWay
<TextBox.Text> <MultiBinding Converter="{StaticResource MaskTextConverter}" Mode="OneWay"> <Binding Path="(nasSetting:TextBoxMaskHelper.MaskText)" ElementName="tbUserName" /> <Binding Path="IsFocused" ElementName="tbUserName" Mode="OneWay"/> </MultiBinding> </TextBox.Text>
相关文章推荐
- WPF技巧(2)绑定到附加属性
- WPF技巧(2)绑定到附加属性
- XAML开发WPF程序入门之附加属性和绑定属性
- WPF依赖属性,绑定通知机制系列补充说明
- WPF DataGrid中列的属性绑定问题
- WPF 自定义控件的依赖属性的绑定方法
- wpf 如何在后台设置附加属性的值
- WPF的xaml中导入其他命名空间以及绑定类属性数据
- WPF依赖属性,绑定通知机制系列补充说明
- WPF 附加属性
- WPF中PasswordBox控件无法绑定Password属性解决办法
- WPF为控件扩展的附加属性不起作用需要注意的地方
- WPF快速入门1-XAML(window、Page、Application、属性、附加属性、特殊字符、保留空白、事件)
- WPF(附加属性)
- WPF中的属性绑定 binding
- WPF绑定不到父控件属性
- WPF菜鸟谈之依赖属性,附加属性(附加《深入浅出WPF》pdf下载)
- WPF绑定各种数据源之元素控件属性
- 模拟实现WPF的依赖属性及绑定通知机制(1)--依赖属性 .
- WPF设置附加属性的值