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

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

问题描述

目前,我将TextBox es绑定为:

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中,创建一个Delegate Command并连接到它.

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天全站免登陆