TextChanged方法里为空有什么作用
MainWindos.xaml文件代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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 MathsOperators
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void calculateClick(object sender, RoutedEventArgs e)
{
try
{
if ((bool)addition.IsChecked)
addValues();
else if ((bool)subtraction.IsChecked)
subtractValues();
else if ((bool)multiplication.IsChecked)
multiplyValues();
else if ((bool)division.IsChecked)
divideValues();
else if ((bool)remainder.IsChecked)
remainderValues();
}
catch (Exception caught)
{
expression.Text = "";
result.Text = caught.Message;
}
}
private void addValues()
{
int lhs = int.Parse(lhsOperand.Text);
int rhs = int.Parse(rhsOperand.Text);
int outcome;
outcome = lhs + rhs;
expression.Text = lhsOperand.Text + " + " + rhsOperand.Text;
result.Text = outcome.ToString();
}
private void subtractValues()
{
int lhs = int.Parse(lhsOperand.Text);
int rhs = int.Parse(rhsOperand.Text);
int outcome;
outcome = lhs - rhs;
expression.Text = lhsOperand.Text + " - " + rhsOperand.Text;
result.Text = outcome.ToString();
}
private void multiplyValues()
{
int lhs = int.Parse(lhsOperand.Text);
int rhs = int.Parse(rhsOperand.Text);
int outcome;
outcome = lhs * rhs;
expression.Text = lhsOperand.Text + " * " + rhsOperand.Text;
result.Text = outcome.ToString();
}
private void divideValues()
{
int lhs = int.Parse(lhsOperand.Text);
int rhs = int.Parse(rhsOperand.Text);
int outcome;
outcome = lhs / rhs;
expression.Text = lhsOperand.Text + " / " + rhsOperand.Text;
result.Text = outcome.ToString();
}
private void remainderValues()
{
int lhs = int.Parse(lhsOperand.Text);
int rhs = int.Parse(rhsOperand.Text);
int outcome;
outcome = lhs % rhs;
expression.Text = lhsOperand.Text + " % " + rhsOperand.Text;
result.Text = outcome.ToString();
}
private void quitClick(object sender, RoutedEventArgs e)
{
this.Close();
}
private void lhsOperand_TextChanged(object sender, TextChangedEventArgs e)
{
}
private void rhsOperand_TextChanged(object sender, TextChangedEventArgs e)
{
}
}
}
MainWindow.xaml.cs代码: Title="Maths Operators" Height="382" Width="367">
<Grid>
<Label Height="31.2766666666667" HorizontalAlignment="Left" Margin="16,20,0,0" Name="lhs" VerticalAlignment="Top" Width="80">left operand</Label>
<Label Height="31" HorizontalAlignment="Right" Margin="0,20,16,0" Name="rhs" VerticalAlignment="Top" Width="85">right operand</Label>
<TextBox Height="26" HorizontalAlignment="Left" Margin="16,57,0,0" Name="lhsOperand" VerticalAlignment="Top" Width="80" TextChanged="lhsOperand_TextChanged" />
<TextBox Height="26" HorizontalAlignment="Right" Margin="0,55,21,0" Name="rhsOperand" VerticalAlignment="Top" Width="80" TextChanged="rhsOperand_TextChanged" /> <StackPanel Margin="108,57,117,160.893333333333" Name="operators">
红字 的这两个表示触发文本的change事件,但是方法里内容为空啊,怎么理解