Skip to content

Instantly share code, notes, and snippets.

@ericsk
Created April 18, 2013 14:48
Show Gist options
  • Select an option

  • Save ericsk/5413319 to your computer and use it in GitHub Desktop.

Select an option

Save ericsk/5413319 to your computer and use it in GitHub Desktop.
改寫 MessageModel 使其資料內容改變時會發出通知
...
public class MessageModel : System.ComponentModel.INotifyPropertyChanged
{
private string _id;
public string Id
{
get { return _id; }
set
{
if (value != _id)
{
_id = value;
NotifyPropertyChanged("Id");
}
}
}
private string _name;
public string Name
{
get { return _name; }
set
{
if (value != _name)
{
_name = value;
NotifyPropertyChanged("Name");
}
}
}
private string _message;
public string Message
{
get { return _message; }
set
{
if (value != _message)
{
_message = value;
NotifyPropertyChanged("Message");
}
}
}
private string _avatarUrl;
public string AvatarUrl
{
get { return _avatarUrl; }
set
{
if (value != _avatarUrl)
{
_avatarUrl = value;
NotifyPropertyChanged("AvatarUrl");
}
}
}
private DateTime _postTime;
public DateTime PostTime
{
get { return _postTime; }
set
{
if (value.CompareTo(_postTime) != 0)
{
_postTime = value;
NotifyPropertyChanged("PostTime");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (null != handler)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment