Mar*_*ter 5 .net c# validation wpf
如果我有数据绑定表单,我如何知道用户是否已修改它(通过在文本框中键入文本,或通过选择组合框中的项目)?我试过挂钩我的文本框的"TextChanged"事件,但问题是,当我的表单参与数据绑定时,"TextChanged"事件触发,过早地将我的表单标记为"脏".
尝试实施
public partial class Window1 : INotifyPropertyChanged
Run Code Online (Sandbox Code Playgroud)
进而
public event PropertyChangedEventHandler PropertyChanged;
public string UserName
{
get { return _UserName; }
set { if (value != _UserName)
{
_UserName = value;
OnNotifyPropertyChanged("UserName");
}}
}
private void OnNotifyPropertyChanged(string property)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(property));
}
Run Code Online (Sandbox Code Playgroud)
和数据绑定一样
<TextBox Text="{Binding UserName}"/>
Run Code Online (Sandbox Code Playgroud)