【发布时间】:2011-10-14 04:09:36
【问题描述】:
我正在尝试禁用一个按钮以拒绝点击此按钮的垃圾邮件。
我使用 Refresh 委托来渲染调用控件,但它显示为已启用。 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;
}
【问题讨论】: