ViewModelのfield変数を削除して、Modelのfieldを使いたいです。
Windows10, VisualStudio2015,C#6.0, Livetの組み合わせで開発しています。
MVVMモデルです。
ViewModelのfieldのxを削除し、ModelのvalueXを使えとのこと。ただ、valueXはprivateなので、publicのValueXを使うのだと思います。
その場合、Propertyに気をつけることはありますか?
現在、ViewModelは、次のようになっています。
これのdouble xを削除するとどのようになりますか?
よろしくご教示ください。
C#
1using System.Globalization; 2 3namespace Livet.Application1.Viewer.View.XYWindow{ 4 public class XYWindowWindowViewModel { 5 private double x;//最終的に削除。 6 public string XTextBoxText { 7 get { 8 return this.x.ToString(CultureInfo.InvariantCulture); 9 } 10 11 set { 12 if (this.XTextBoxText == value) 13 return; 14 15 double v; 16 if (!double.TryParse(value, out v)){ 17 this.RaisePropertyChanged(() => this.XTextBoxText); 18 return; 19 } 20 this.x = v; 21 this.RaisePropertyChanged(() => this.XTextBoxText); 22 } 23 } 24 } 25} 26 27
Modelは次のとおりです。
C#
1using System.ComponentModel; 2 3namespace Livet.Common.Controls{ 4 public class Parameter : INotifyPropertyChanged 5 { 6 private double valueX;//これを使うらしい。 7 8 public double ValueX {//実際はpublicなのでこちらを使う? 9 get { 10 return this.valueX; 11 } 12 set { 13 if (this.valueX.Equals(value)) 14 return; 15 16 this.valueX = value; 17 18 this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(this.PropertyName(() => this.ValueX))); 19 } 20 } 21 22 public event PropertyChangedEventHandler PropertyChanged; 23 24 public override bool Equals(object obj) 25 { 26 if (this == obj) return true; 27 if (obj == null) return false; 28 return true; 29 } 30 } 31}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/07/14 07:07