我有一个在这里启用和禁用按钮的方法。我输入一个数字时应该执行if-else阻止lbDivide 'öde','0'和'00' 按钮应处于活动状态,但只能激活 öde 按钮。我该怎样解决这个问题?
öde=付款
KişiSayısı=有多少人?
private void Bol_Click(object sender, RoutedEventArgs e)
{
lbDivide.Text = "0";
btnBol.Opacity = 0.5;
btnBol.IsEnabled = false;
lbPayment.Visibility = Visibility.Hidden;
if (lbDivide.Text == "0")
{
btnQr.Opacity = 0.5;
btnQr.IsEnabled = false;
zero.Opacity = 0.2;
zero.IsEnabled = false;
double_zero.IsEnabled = false;
double_zero.Opacity = 0.2;
}
else
{
btnQr.Opacity = 1;
btnQr.IsEnabled = true;
zero.Opacity = 1;
double_zero.Opacity = 1;
zero.IsEnabled = true;
double_zero.IsEnabled = true;
}
答案 0 :(得分:1)
我想我知道错误在哪里。
private void Bol_Click(object sender, RoutedEventArgs e)
{
lbDivide.Text = "0"; /// in this line of code you're basically setting lbDivide.text to be 0 every time the button is clicked, so the else condition will never be met.
btnBol.Opacity = 0.5;
btnBol.IsEnabled = false; /// you're basically disabling the button after the first click.
lbPayment.Visibility = Visibility.Hidden;
if (lbDivide.Text == "0")
{
btnQr.Opacity = 0.5;
btnQr.IsEnabled = false;
zero.Opacity = 0.2;
zero.IsEnabled = false;
double_zero.IsEnabled = false;
double_zero.Opacity = 0.2;
}
else
{
btnQr.Opacity = 1;
btnQr.IsEnabled = true;
zero.Opacity = 1;
double_zero.Opacity = 1;
zero.IsEnabled = true;
double_zero.IsEnabled = true;
}
}
答案 1 :(得分:-1)
if(lbDivide.Text ==" 0")改变if(lbDivide.Text.Equals(" 0"))