【WPF系列】-TextBox常用知识点

DataBinding中更新数据源的时机

 

TextBox .Text 属性的默认 UpdateSourceTrigger 值为 LostFocus。这意味着如果应用程序的 TextBox 包含数据绑定 TextBox.Text 属性,则直到 TextBox 失去焦点(例如,将鼠标移到TextBox 外单击时),键入到 TextBox 中的文本才能更新源。

 

如果希望在键入过程中更新源,请将该绑定的 UpdateSourceTrigger 设置为 PropertyChanged。 在下面的示例中,TextBoxTextBlock 的 Text 属性都绑定到同一源属性。 将 TextBox绑定的 UpdateSourceTrigger 属性设置为 PropertyChanged

简单数据绑定示例屏幕快照

<Label>Enter a Name:</Label>
<TextBox>
  <TextBox.Text>
    <Binding Source="{StaticResource myDataSource}" Path="Name"
             UpdateSourceTrigger="PropertyChanged"/>
  </TextBox.Text>
</TextBox>

<Label>The name you entered:</Label>
<TextBlock Text="{Binding Source={StaticResource myDataSource}, Path=Name}"/>

源自:如何:控制文本框文本更新源的时间

 

 

 

高级实例:

通过dataTriger来给TextBox焦点

Using XAML to Set Focus on a Textbox in WPF Desktop Applications

passcode_entry_workflow

<Style x:Key="LayoutRoot" TargetType="Grid">
        <Style.Triggers>
            <!--these are the triggers that make the code cursor jump from box 1 to box 2 to box 3.-->
            <DataTrigger Binding="{Binding ElementName=CodeDigit1, Path=Text.Length}" Value="1">
                <Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=CodeDigit2}"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding ElementName=CodeDigit2, Path=Text.Length}" Value="1">
                <Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=CodeDigit3}"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding ElementName=CodeDigit3, Path=Text.Length}" Value="1">
                <Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=CodeDigit4}"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding ElementName=CodeDigit4, Path=Text.Length}" Value="1">
                <Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=ConnectButton}"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>

转载于:https://www.cnblogs.com/HQFZ/p/4142941.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值