[英]Wpf Button IsEnabled not working
i have a method that enabling and disabling button in here.My if-else block should do when enter a number to lbDivide the 'öde', '0' and '00' buttons should be active but only activing öde button.How do i solve this ? 我在这里有一种启用和禁用按钮的方法。当输入数字以对lbDivide进行操作时,我的if-else块应该起作用``öde'',``0''和``00''按钮应该处于活动状态,但只能激活öde按钮。解决这个问题?
öde = make payment öde=付款
Kişi Sayısı = How many person? 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;
}
I think I know where the error is. 我想我知道错误在哪里。
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;
}
}
将if(lbDivide.Text ==“ 0”)更改为if(lbDivide.Text.Equals(“ 0”))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.