Last active
September 15, 2016 12:58
-
-
Save kuttsun/375f36f971719abe4ccde726f410b16b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// MainWindowに対するViewModel | |
/// </summary> | |
class MainWindowViewModel : ViewModelBase | |
{ | |
// バインディングされる値を保持するフィールド | |
private string sampleText_; | |
// バインディング対象のプロパティ | |
public string SampleText | |
{ | |
get | |
{ | |
return sampleText_; | |
} | |
set | |
{ | |
sampleText_ = value; | |
// 変更をViewに通知する | |
OnPropertyChanged("SampleText"); | |
// ラベルの値も連動させる | |
SampleLabel = value; | |
} | |
} | |
// バインディングされる値を保持するフィールド | |
private string sampleLabel_ = ""; | |
// バインディング対象のプロパティ | |
public string SampleLabel | |
{ | |
get | |
{ | |
return sampleLabel_; | |
} | |
set | |
{ | |
sampleLabel_ = value; | |
// 変更をViewに通知する | |
OnPropertyChanged("SampleLabel"); | |
} | |
} | |
/// <summary> | |
/// コンストラクタ | |
/// </summary> | |
public MainWindowViewModel() | |
{ | |
SampleText = "Sample"; | |
SampleLabel = "Sample"; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// MainWindowに対するViewModel | |
/// </summary> | |
class MainWindowViewModel : ViewModelBase | |
{ | |
// バインディングされる値を保持するフィールド | |
private string sampleText_; | |
// バインディング対象のプロパティ | |
public string SampleText | |
{ | |
get | |
{ | |
return sampleText_; | |
} | |
set | |
{ | |
sampleText_ = value; | |
// 変更をViewに通知する | |
OnPropertyChanged(nameof(SampleText)); | |
// ラベルの値も連動させる | |
SampleLabel = value; | |
} | |
} | |
// バインディングされる値を保持するフィールド | |
private string sampleLabel_ = ""; | |
// バインディング対象のプロパティ | |
public string SampleLabel | |
{ | |
get | |
{ | |
return sampleLabel_; | |
} | |
set | |
{ | |
sampleLabel_ = value; | |
// 変更をViewに通知する | |
OnPropertyChanged(nameof(SampleLabel)); | |
} | |
} | |
/// <summary> | |
/// コンストラクタ | |
/// </summary> | |
public MainWindowViewModel() | |
{ | |
SampleText = "Sample"; | |
SampleLabel = "Sample"; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// ViewModelの親クラス | |
/// プロパティが変更されたことを通知するため、INotifyPropertyChangedインターフェースを実装する | |
/// プロパティ変更時OnPropertyChangedを呼び出す | |
/// </summary> | |
class ViewModelBase : INotifyPropertyChanged | |
{ | |
public event PropertyChangedEventHandler PropertyChanged; | |
/// <summary> | |
/// プロパティの変更をViewに通知 | |
/// </summary> | |
/// <param name="propertyName">プロパティ名</param> | |
protected void OnPropertyChanged(string propertyName) | |
{ | |
if (PropertyChanged != null) | |
{ | |
PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// ViewModelの親クラス | |
/// プロパティが変更されたことを通知するため、INotifyPropertyChangedインターフェースを実装する | |
/// プロパティ変更時OnPropertyChangedを呼び出す | |
/// </summary> | |
class ViewModelBase : INotifyPropertyChanged | |
{ | |
public event PropertyChangedEventHandler PropertyChanged; | |
/// <summary> | |
/// プロパティの変更をViewに通知 | |
/// </summary> | |
/// <param name="propertyName">プロパティ名</param> | |
protected void OnPropertyChanged(string propertyName) | |
{ | |
PropertyChanged?.InvokeChanged(this, new PropertyChangedEventArgs(propertyName)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment