zoukankan      html  css  js  c++  java
  • WPF 绑定到附加属性 绑定到只读属性

    绑定有两个需要注意的地方

    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>
  • 相关阅读:
    原生代码实现Promise
    HTTP与HTTPS的区别
    windows常用命令-长期更新
    git 常用命令
    原型和原型链
    vue 中一些API 或属性的常见用法
    移动端屏幕适配
    Nuxt.js(开启SSR渲染)
    vue+element-ui 实现分页(根据el-table内容变换的分页)
    vue中引入jQuery和bootstrap
  • 原文地址:https://www.cnblogs.com/xiaokang088/p/2607722.html
Copyright © 2011-2022 走看看