我想禁用一个按钮来拒绝点击此按钮上的垃圾邮件。刷新WPF控制代码
我使用了一个Refresh委托Render调用该控件,但它显示为启用。 connect() - Methode在按钮显示为启用时需要约4秒钟的时间。
问题在哪里?
public static class ExtensionMethods
{
private static Action EmptyDelegate = delegate() { };
public static void Refresh(this UIElement uiElement)
{
uiElement.Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate);
}
}
private void buttonConnect_Click(object sender, RoutedEventArgs e)
{
this.Cursor = Cursors.Wait;
buttonConnect.IsEnabled = false;
buttonConnect.Refresh();
if (buttonConnect.Content.Equals("Connect"))
{
connect();
}
else
{
disconnect();
}
buttonConnect.IsEnabled = true;
buttonConnect.Refresh();
this.Cursor = Cursors.Arrow;
}
+1我见过很多答案对这个问题的SO。这是我见过的最灵活可靠的。 –