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入门6 —— 流程控制
    Python入门5 —— 基本运算符
    Python入门4 —— 输入与输出
    实用小工具 下载链接
    [笔记] BGP in the Data Center (O'Reilly 2017)
    数据中心网络:Spine-Leaf 架构设计综述(2016)
    Using Open vSwitch* with DPDK for Inter-VM NFV Applications
    hung_task
    TCPDUMP and IPv6 and perf trace --no-syscalls
    Go非缓冲/缓冲/双向/单向通道
  • 原文地址:https://www.cnblogs.com/shawnzxx/p/3069222.html
Copyright © 2011-2022 走看看