你能为.Net WPF中的TextBox的TextChanged事件建议类似的事件吗?

时间:2011-07-05 08:35:54

标签: .net wpf

我必须对WPF文本框的每个textchange事件进行复杂的计算,是否有类似的事件?

1 个答案:

答案 0 :(得分:3)

您可以使用Binding,并确保触发绑定项的任何更改:

<TextBox Text="{Binding Path=X, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>

然后在您的viewModel中,您可以根据该更改进行计算(您的ViewModel应该实现INotifyPropertyChanged

public int MyProperty
        {
            get
            {
                return myVar ;
            }
            set
            {
                myVar = value;
                OnPropertyChanged("MyProperty") ;

                //Fire off calculation in another thread in here

            }
        }
相关问题