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

  • 相关阅读:
    python:利用asyncio进行快速抓取
    os.path.exists(path) 和 os.path.lexists(path) 的区别
    isdigit()判断是不是数字
    switf资源
    51cto培训课程
    51cto运维培训课程
    Python: 在Unicode和普通字符串之间转换
    VC++ CopyFile函数使用方法
    Eclipse断点调试
    AFNetworking2.0后 进行Post请求
  • 原文地址:https://www.cnblogs.com/shawnzxx/p/3069222.html
Copyright © 2011-2022 走看看