Click here to Skip to main content
14,640,670 members
Rate this:
Please Sign up or sign in to vote.
See more:
I've created a Mortgage Calculator via WPF on visual studio 2012. The design looks like this:

Enter Loan amount: TextBox here

Enter Loan Duration:

15 years(Radio Button)

30 years(Radio Button)

Other(Radio Button) with TextBox

Select Interest Rate: ComboBox here

Button here to calculate

The issue is i'm having trouble with coding the math formula properly with the textbox, radio buttons, and combobox. Im not sure how to include the Radio Button options(15,30,other)that is selected when running the program into the formula properly.

This is the code I have: I know that im not incorporating the radiobox options into the formula bellow. Currently when I run the program i'm getting the validation error that i've setup: "Please enter a valid length" and "Please enter a valid interest rate"

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplicationCALC
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
        public MainWindow()

        private void ButtonCal_Click(object sender, RoutedEventArgs e)
            double p;
            float r;
            double n;

            if (!double.TryParse(Textboxloan.Text, out p))
                MessageBox.Show("Please Enter a Valid Amount", "Incorrect Data");
            if (!double.TryParse(Textboxother.Text, out n))
                MessageBox.Show("Please Enter a Valid Length. \n Amount given is: " + Textboxother.Text);
            if (!float.TryParse(InterestRateCB.SelectedItem.ToString(), out r))
                MessageBox.Show("Please Enter a Valid Interest Rate", "Incorrect Rate");

            double top = p * r / 1200.00;
            double bottom = 1 - Math.Pow(1.0 + r / 1200.0, -12.0 * n);
            double monthly = top / bottom;
            string MonthPay = string.Format("The amount of the monthly payment is: {0:c}", monthly);

        private void Radio_Checked(object sender, RoutedEventArgs e)
            if (RadioOther.IsChecked == true)
                Textboxother.IsEnabled = true;
                Textboxother.IsEnabled = false;

        private void InterestRateCB_SelectionChanged(object sender, SelectionChangedEventArgs e)
            ComboBoxItem cpi = InterestRateCB.SelectedItem as ComboBoxItem;
            string str = (string)cpi.Content;

[no name] 19-May-14 14:35pm
What do you mean "you don't know how"? Use the radio button IsChecked property just like you are already doing other places.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100