文本框绑定到 LostFocus 和属性更新 [英] Textbox Binding to both LostFocus and Property Update

查看:20
本文介绍了文本框绑定到 LostFocus 和属性更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我绑定到我的 TextBoxes 为:

Currently I bind to my TextBoxes as:

Text="{Binding DocValue,
         Mode=TwoWay,
         ValidatesOnDataErrors=True,
         UpdateSourceTrigger=PropertyChanged}"

这非常适合让每次击键都进行按钮状态检查(我想要的).

This works great in getting every keystroke to do button status checking (which I want).

此外,我想跟踪 TextBox 上的 LostFocus 事件(通过绑定)并进行一些额外的计算,这些计算对于每次击键来说可能过于密集.

In addition, I would like to track the LostFocus event on the TextBox (through binding) and do some additional calculations that might be too intensive for each keystroke.

有人对如何实现两者有想法吗?

Anyone have thoughts on how to accomplish both?

推荐答案

我想我找到了解决方案...我创建了一个复合命令并将其用于额外的通信.

I think I have found a solution... I created a composite command and use that for the additional communication.

命令定义

public static CompositeCommand TextBoxLostFocusCommand = new CompositeCommand();

我的文本框

private void TextboxNumeric_LostFocus(object sender, RoutedEventArgs e)
{
    if (Commands.TextBoxLostFocusCommand.RegisteredCommands.Count > 0)
    {
        Commands.TextBoxLostFocusCommand.Execute(null);
    }
}

然后在我的 ViewModel 中,我创建一个委托命令并连接到它..

then in my ViewModel, I create a Delegate Command and wire to it..

似乎它正在工作,想知道是否有更好的方法.一个缺点是每个文本框都会触发它,而不仅仅是附加到我想要计算的公式的项目.可能需要想办法改进这一点.

It seems like it is working, wonder if there is a better way. One downfall to this is that every Textbox will fire this, not just my items that are attached to formulas I want to calculate. Might need to think of ways to improve on this.

这篇关于文本框绑定到 LostFocus 和属性更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆