public class ViewModel : INotifyPropertyChanged
{
private string name;
public string Name
{
get
{
return name;
}
set
{
if (name != value)
{
name = value;
OnPropertyChanged("Name");
}
}
}
protected void OnPropertyChanged(string propertyname)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyname));
}
}
public PropertyChangedEventHandler PropertyChanged;
}
public partial class MainWindow : Window
{
private ViewModel vm;
public MainWindow()
{
InitializeComponent();
vm = new ViewModel { Name = "Shahrukh Khan" };
DataContext = vm;
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
vm.Name = "Salman Khan";
}
}
當我運行下面的代碼我得到這個錯誤:INotifyPropertyChange接口錯誤
INotifyUnderstandingYoutube.ViewModel
does not implement interface memberSystem.ComponentModel.INotifyPropertyChanged.PropertyChanged
我不明白這背後的原因是什麼?任何人都可以請解釋什麼是錯誤?
是的,它現在工作很棒:) – TheSpy