zoukankan      html  css  js  c++  java
  • Binding中的TargetNullValue属性(项目)

    Wilma项目中的例子:

    View Code
     1 <TextBox Width="28"
     2                                  Margin="15,5,0,5"
     3                                  HorizontalAlignment="Left"
     4                                  VerticalContentAlignment="Center"
     5                                  KeyboardNavigation.TabIndex="2"
     6                                  FontFamily="/Halliburton.Wilma;component/Fonts/#Univers 55"
     7                                  FontSize="10pt"
     8                                  MaxLength="2"
     9                                  Padding="2,3"
    10                                  Style="{StaticResource Gray_TextBox_Style}"
    11                                  Template="{StaticResource Base_TextBox_Template}"
    12                                  Text="{Binding Path=CurTool.SleepDuration,
    13                                                 UpdateSourceTrigger=PropertyChanged,
    14                                                 TargetNullValue={x:Static sys:String.Empty}}"
    15                                                 local:Masking.Mask="^\d*$">
    16                                 <i:Interaction.Triggers>
    17                                     <i:EventTrigger EventName="LostFocus">
    18                                         <prism:InvokeCommandAction Command="{Binding VerifySleepDuration}" />
    19                                     </i:EventTrigger>
    20                                 </i:Interaction.Triggers>
    21                             </TextBox>

    其中TargetNullValue和Binding的Path指定的后台property做对应,当后台property为null时,这个TextBox.Text={x:Static sys:String.Empty}表现为文档框里是的empty。相反如果文档框里是Empty的话后台的property就被set去‘null’

    参考:

    <TextBox Text="{Binding Total, TargetNullValue=0.00}" />

        The above code will set the Total property to null if the value is entered is 0.00 and if Total property is null it will display 0.00. The same functionality can be achieved by checking for null in the property getter and setters, but this is very handy and you don't have to do it in all the places where you want to achieve this behaviour.

    MSDN:http://msdn.microsoft.com/en-us/library/system.windows.data.bindingbase.targetnullvalue.aspx

  • 相关阅读:
    STL中set求交集、并集、差集的方法
    Vijos 1308 埃及分数(迭代加深搜索)
    POJ 1161 Walls(Floyd , 建图)
    UVa 1601 万圣节后的早晨
    dp之完全背包
    dp之取数字问题
    dp之最长公共子序列
    枚举排列
    poj 3187 暴力枚举
    poj 2431 优先队列,贪心
  • 原文地址:https://www.cnblogs.com/shawnzxx/p/3069222.html
Copyright © 2011-2022 走看看