WPF怎样实现数据库数据更新后实现INotifyPropertyChanged-CSDN论坛
1个回答
展开全部
首先创先一个实体类
public class MyClass : INotifyPropertyChanged
{
private static string _myString = "sdfdsfssdfsdfsdfdsf";
public string MyString
{
get { return _myString; }
set
{
_myString = value;
OnPropertyChanged("MyString");
}
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}
//然后把这个实体类绑定到页面的 DataContext
<TextBox Text="{Binding MyString}"/>
public class MyClass : INotifyPropertyChanged
{
private static string _myString = "sdfdsfssdfsdfsdfdsf";
public string MyString
{
get { return _myString; }
set
{
_myString = value;
OnPropertyChanged("MyString");
}
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}
//然后把这个实体类绑定到页面的 DataContext
<TextBox Text="{Binding MyString}"/>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询