我有一个名为“验证”的按钮。单击时应将其内容更改为“正在验证...”,处理完成后应显示“已验证”。我们应该如何做到这一点?我是 wpf 的新手。任何帮助将不胜感激。
private void btnVerify_Click(object sender, RoutedEventArgs e)
{
btnVerify.Content = new BitmapImage(new Uri("Verifying.png", UriKind.Relative));
VerifyData(); // this takes almost few seconds to few minutes
btnVerify.Content = new BitmapImage(new Uri("Verified.png", UriKind.Relative));
}
最佳答案
因为您是 WPF 的新手,所以我假设您没有使用 MVVM。在这种情况下:
Hook 到 Click
事件和方法中:
OnVerifyClick(object sender, RoutedEventArgs e)
{
Button verifyButton = sender as Button;
if(verifyButton == null) { return; }
verifyButton.Content = "Verifying...";
DoProcessing();
verifyButton.Content = "Verified";
}
关于c# - 单击它更改内容并返回原始状态的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9368343/