Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
.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
You can’t perform that action at this time.