我已完成大部分代码,但现在我不知道在何处以及如何开始计算月付款。 我已将输入传递给局部变量。 我确实尝试在底部计算。所以请帮助我。
答案 0 :(得分:1)
你没有使用MVVM模式,所以你的回调应该在'代码隐藏'中。使用WPF自动完成:
MortgageCalculator.MainWindow
<Button Click="HERE!!!">
<Button.Effect>
<DropShadowEffect BlurRadius="2" Color="#FF7E7979" ShadowDepth="2"/>
</Button.Effect>
</Button>
它会在后面的代码中创建回调(而不是像你一样在窗口中创建)。 在MortgageCalculator.MainWindow.xaml.cs:
/// <summary>
/// Interaction logic for MortgageCalculator.xaml
/// </summary>
public partial class MortgageCalculator : UserControl
{
public MortgageCalculator()
{
InitializeComponent();
}
private void somecallback(object sender, RoutedEventArgs e)
{
}
}
答案 1 :(得分:0)
记下已注释或移动的return
语句。此外,付款计算的更正版本:
private void btnsubmit_Click(object sender, RoutedEventArgs e)
{
{
double monthlypayment = 0;
//Tryparse for principal amount with error Red texbox
if (String.IsNullOrEmpty(txtprincipal.Text) || !double.TryParse(txtprincipal.Text, out principal))
{
txtprincipal.BorderBrush = new SolidColorBrush(Colors.Red);
return;
}
else
txtprincipal.BorderBrush = new SolidColorBrush(Colors.Black);
//Validate radio button
if (rad10years.IsChecked.Value)
{
years = 10;
//return;
}
else if (rad20years.IsChecked.Value)
{
years = 20;
//return;
}
else if (rad30years.IsChecked.Value)
{
years = 30;
//return;
}
else if (radother.IsChecked == true)
{
if (!double.TryParse(txtother.Text, out years))
{
MessageBox.Show("Not a Valid year.");
return;
}
//return;
}
else
{
MessageBox.Show("Please select number of years.");
stkrdobtns.Background = new SolidColorBrush(Colors.Red);
return;
}
//monthlypayment = ((principal * rate) / 1200) / Math.Pow(1 - (1.0 + rate / 1200), (-12.0 * years));
var r = rate / 1200.0;
var n = years * 12.0;
monthlypayment = principal * ((r * Math.Pow((1 + r), n)) / (Math.Pow(1 + r, n) - 1));
string MonthPay = string.Format("The amount of the monthly payment is: {0:c}", monthlypayment);
MessageBox.Show(MonthPay);
}
}