【问题标题】:How to disable and enable a button dynamically?如何动态禁用和启用按钮?
【发布时间】:2019-04-21 06:39:41
【问题描述】:

在我的 UWP 中,我有一个 TextBox 和一个 Button. 我想在 TextBox 为空时禁用 Button

我在启动时尝试过这个-

if (string.IsNullOrEmpty(hmmtxtBox.Text))
{
    hmmbtn.IsEnabled = false;
}

private void HmmtxtBox_TextChanged(object sender, TextChangedEventArgs e)
{
    hmmbtn.IsEnabled = true;
}

它可以正常工作,但是当我清除 TextBox 时,Button 仍然启用。如果TextBox 为空,我想禁用,反之亦然。

【问题讨论】:

    标签: c# xaml button uwp


    【解决方案1】:

    试试这个:

    private void HmmtxtBox_TextChanged(object sender, TextChangedEventArgs e)
    {
        hmmbtn.IsEnabled = HmmtxtBox.Text.Length > 0;
    }
    

    【讨论】:

      猜你喜欢
      • 2020-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-17
      • 1970-01-01
      相关资源
      最近更新 更多