C#/WPF我不知道';I don’我不知道如何以及在哪里计算每月的按揭付款
我已经完成了大部分代码,但现在我不知道在哪里以及如何开始计算每月付款。 我已将输入传递给局部变量。C#/WPF我不知道';I don’我不知道如何以及在哪里计算每月的按揭付款,c#,.net,wpf,xaml,C#,.net,Wpf,Xaml,我已经完成了大部分代码,但现在我不知道在哪里以及如何开始计算每月付款。 我已将输入传递给局部变量。 我确实试过在底部计算。因此,请帮助我。您没有使用MVVM模式,因此您的回调应该在“代码隐藏”中。请在以下位置使用WPF自动完成: MortgageCalculator.main窗口 <Button Click="HERE!!!"> <Button.Effect> <DropShadowEffect BlurRadius="2" Color="#
我确实试过在底部计算。因此,请帮助我。您没有使用MVVM模式,因此您的回调应该在“代码隐藏”中。请在以下位置使用WPF自动完成: MortgageCalculator.main窗口
<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)
{
}
}
//
///MortgageCalculator.xaml的交互逻辑
///
公共部分类MortgageCalculator:UserControl
{
公共抵押计算器()
{
初始化组件();
}
私有void somecallback(对象发送方,RoutedEventArgs e)
{
}
}
注意已注释掉或移动的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);
}
}
这个代码有什么问题?您是否收到任何错误或异常?我不知道我该如何回去编辑这篇文章,但是当我输入所有的值并点击提交按钮时,它没有显示任何内容。我认为我的计算是错误的(以编写的方式)。在
else
语句后的三行周围没有括号,因此执行永远不会到达计算或MessageBox.Show(MonthPay)
行。IDE可能会给你一个关于无法访问的代码的警告。我不确定你是否在谈论下面缺少括号的代码。如果你是比我已经把它周围的括号,它仍然不工作。else{MessageBox.Show(“请选择年数”);stkrdobtns.Background=newsolidColorBrush(Colors.Red);return;}这不会编译monthlypayement
定义为int
,计算产生一个double
。即使解决了这个问题,并且最后一个else
子句正确地括起了mothypayment
计算,仍然无法实现。如果需要注释掉案例,则前3个案例中的返回
s。一旦你这样做了,计算就完成了,但总是产生0
,所以你的方程也有问题。