我正在尝试禁用一个按钮,以避免对该按钮进行垃圾点击。
我使用了Refresh委托来Render调用控件,但按钮仍然是启用状态。 connect()方法需要大约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;
}