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

  • 相关阅读:
    离线计算框架 MapReduce
    Hadoop概述
    Linux之rpm/yum
    Linux之磁盘分区
    利用CMD合并多个VOB文件
    android中的simple_list_item
    jquery中的跨域-jsonp格式
    安卓代码中设置ImageView属性
    Android中常用的Adapter的种类和用法
    C#导入excel文件到oracle的方法
  • 原文地址:https://www.cnblogs.com/shawnzxx/p/3069222.html
Copyright © 2011-2022 走看看