Là một thực hành tốt nhất, chuyển đổi lĩnh vực công cộng của bạn để tính bằng tay và thực hiện class
với INotifyPropertyChanged
interface
để nâng cao một sự thay đổi event
của bạn.
EDIT: Bởi vì bạn đề cập đến 100 lĩnh vực tôi sẽ đề nghị bạn để cấu trúc lại mã của bạn như thế nào trong câu trả lời tuyệt vời này: Tools for refactoring C# public fields into properties
Dưới đây là một ví dụ của nó:
private string _customerNameValue = String.Empty;
public string CustomerName
{
get
{
return this._customerNameValue;
}
set
{
if (value != this._customerNameValue)
{
this._customerNameValue = value;
NotifyPropertyChanged();
}
}
}
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
Kiểm tra này ra: INotifyPropertyChanged Interface
Nguồn
2013-04-15 14:23:51
Đây có phải là cách gỡ lỗi hoặc là để cập nhật giao diện người dùng? Câu trả lời sẽ khác nhau cho phù hợp. –
Để cập nhật giao diện người dùng và thực hiện nhiều việc khác – Nickon