私は Loan Calculator を作成しており、相互に反映させようとしている 3 つの TextBox があります。TextBoxes の 1 つの入力を変更した後、プログラムにある計算ボタンを押すか、TextBox がフォーカスを失った後に、入力に基づいて他の 2 つを再計算します。
私が持っている 3 つの TextBoxes は、実行中のプログラムで設定される特定の値と、実行時に変更できる機能にバインドされています。
<TextBox Width="55" Height="23" Style="{StaticResource ResourceKey=StandardTextbox}" Text="{Binding StringFormat={}{0:P}, Path=CurrentLoan.PropertyTaxRate, Converter={StaticResource TextBoxToDecimalConverter1}}"/>
<TextBox Width="65" Height="23" Style="{StaticResource ResourceKey=StandardTextbox}" Text="{Binding StringFormat={}{0:C}, Path=CurrentLoan.PropertyTaxMonth, Converter={StaticResource TextBoxToDecimalConverter1}}"/>
<TextBox Width="65" Height="23" Style="{StaticResource ResourceKey=StandardTextbox}" Text="{Binding StringFormat={}{0:C}, Path=CurrentLoan.PropertyTaxYear, Converter={StaticResource TextBoxToDecimalConverter1}}"/>
CurrentLoan.PropertyTaxRate = .012;
CurrentLoan.PropertyTaxMonth = 250;
CurrentLoan.PropertyTaxYear = 3000;
SharedValues.HomeValue = 250000;
価値が 250,000 ドルで税率が 1.2% の住宅の場合、年間の支払いは 3,000 ドル (250,000 * .012) で、毎月の支払いは 250 ドル (3,000 / 1 年の 12 か月) です。
また、次のようにプロパティが既に宣言されています。
public double PropertyTaxRate
{
get { return _propertyTaxRate; }
set { SetValueAndNotify(() => PropertyTaxRate, ref _propertyTaxRate, (value > 1) ? value / 100 : value); }
}
public double PropertyTaxMonth
{
get { return _propertyTaxMonth; }
set { SetValueAndNotify(() => PropertyTaxMonth, ref _propertyTaxMonth, value); }
}
public double PropertyTaxYear
{
get{ return _propertyTaxYear; }
set { SetValueAndNotify(() => PropertyTaxYear, ref _propertyTaxYear, value); }
}
SetValueAndNotify メソッドは単にバッキング プロパティに値を設定し、INotifyPropertyChanged を使用してプロパティが変更されたことを GUI に通知します。
PropertyTaxYear プロパティを $6,000 に変更した場合、PropertyTaxMonth を $500 に変更し、PropertyTaxRate を 2.4% に変更するとします。これを行う方法とプロパティを相互に反映させる方法についてアイデアを持っている人はいますか? ご意見をお寄せいただきありがとうございます。