æè¿ãã¼ã¿ãã«ã©ã¤ãã©ãªããã¤ãã§ãï¼ä½ããã¤ãããããã¨ããã¨ãMicrosoft.Bcl.AsyncãNuGetã§è¿½å ããã°async/awaitã使ããä¸ã«CallerMemberNameAttributeã¨ãC# 5.0ã®æ©è½ã使ãã¡ããã¨ããã§ãããããã以ä¸ã®å¹ åºããã©ãããã©ã¼ã ã§ã
- Silverlight 4以ä¸
- WP7.5以ä¸
- .NET 4以ä¸
- WinRT
ããã¯ããããã¼ã¿ãã«ã©ã¤ãã©ãªã«å ¥ããããã®ã¯ã¬ã·ã¬ã·å ¥ãã¦ããã®ãä»ããæ¤è¨ãã¯ããã¦ãæ©ãã¯ãªãã¨æãã¾ããæ©ãã¯ãªãã¨ãã¡ãã£ã¨å¼±æ°ãªã®ã¯Microsoft.Bcl.Asyncããã¾ã æ£å¼ãªãªã¼ã¹ãããªãããã§ãããä»äºã§ã¯ä½¿ããã«ã試ãç¨åº¦ã«è§¦ãã¦ãããããã§ã¡ããã©ããã®ããªã¨æãã¾ãã
ã¨ãããããæåã«ã±ã£ã¨æãã¤ããã®ãINotifyPropertyChangedã®å®è£ ã®åºæ¬ã¯ã©ã¹ãããã¤ã¯ããã¼ã¿ããªãã£æ群ã§ãããSLã§ãWPã§ã.NET Fwã§ãWinRTã§ãä¸çªããæ¸ããã¦ãã³ã¼ãã®ä¸ã¤ã ã¨æãã¾ãã
using System.ComponentModel; using System.Runtime.CompilerServices; public abstract class NotificationObject : INotifyPropertyChanged { protected NotificationObject() { } public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { var h = this.PropertyChanged; if (h != null) { h(this, new PropertyChangedEventArgs(propertyName)); } } }
ããã«ãWindows ã¹ã㢠ã¢ããªã®ãã³ãã¬ã¼ãã§ä½ã£ãæã«è¿½å ãããBindableBaseã®SetPropertyã¿ãããªã¡ã½ããã追å ãã¦ããã¾ãããã
public abstract class NotificationObject : INotifyPropertyChanged { protected NotificationObject() {} public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { var h = this.PropertyChanged; if (h != null) { h(this, new PropertyChangedEventArgs(propertyName)); } } protected bool SetProperty<T>(ref T store, T value, [CallerMemberName] string propertyName = null) { if (Equals(store, value)) { return false; } store = value; this.OnPropertyChanged(propertyName); return true; } }
ãããªã¯ã©ã¹ãä½ã£ã¦ããã¨ããã¼ã¿ãã«ã©ã¤ãã©ãªã®å¯¾è±¡ã®ãã¼ã¸ã§ã³ããå
±éã«ä½¿ãã¡ããINotifyPropertyChangedã®å®è£
ã¯ã©ã¹ã®åºæ¥ä¸ããã
å°ããªãã¨ãããã¤ãã¤ã¨ãã
使ãæ¹
ããã§SL4以ä¸, WP7.5以ä¸, .NET 4以ä¸, WinRTã§ãããªã«ãã£ããã¨ããããã£ãå®ç¾©ã§ãã¡ããã¾ããï¼
public class Person : NotificationObject { private string name; public string Name { get { return this.name; } set { this.SetProperty(ref name, value); } } }