Skip to content

Instantly share code, notes, and snippets.

@Grabacr07
Created August 28, 2015 15:58
Show Gist options
  • Save Grabacr07/bab0002433709ec3c199 to your computer and use it in GitHub Desktop.
Save Grabacr07/bab0002433709ec3c199 to your computer and use it in GitHub Desktop.
.NET Framework 4.5.1 以降でビルドする場合は CurrentMetricUnit と CurrentImperialUnit の set アクセサーは public にしてください
public class MainWindowViewModel : ViewModel
{
private double _metricValue, _imperialValue;
public ICommand ImperialUnitToMetric { get; private set; }
public ICommand MetricToImperialUnit { get; private set; }
public MetricUnit CurrentMetricUnit { get; set; }
public ImperialUnit CurrentImperialUnit { get; set; }
public double MetricValue
{
get { return this._metricValue; }
set
{
this._metricValue = value;
this.OnPropertyChanged();
}
}
public double ImperialValue
{
get { return this._imperialValue; }
set
{
this._imperialValue = value;
this.OnPropertyChanged();
}
}
public MainWindowViewModel()
{
this.CurrentMetricUnit = MetricUnit.Units.First();
this.CurrentImperialUnit = ImperialUnit.Units.First();
this.MetricToImperialUnit = new DelegateCommand(
() => this.ImperialValue = this.CurrentImperialUnit.FromMetricUnit(
this.CurrentMetricUnit, this.MetricValue));
this.ImperialUnitToMetric = new DelegateCommand(
() => this.MetricValue = this.CurrentMetricUnit.FromImperialUnit(
this.CurrentImperialUnit, this.ImperialValue));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment