按钮没有更新

时间:2015-12-30 14:26:58

标签: c# wpf button text

我在托盘中的红球附近有一个非常简单的窗口(见下图)

enter image description here

当我点击退出按钮(esci)时,我想在序列化时更改两个底部的内容

private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
  string strButtonName = (sender as Button).Name;

  switch (strButtonName.ToUpper())
  {
    case "BTEXIT":
      string strError;
      this.btShow.Content = "Serializing";
      this.btExit.Content = "Please wait";
      this.UpdateLayout();
      Serializers.Logger.WriteLog_Reflection<PCDmisLogEntry>;
      System.Threading.Thread.Sleep(2000);<---simulates a long serialization process
      Environment.Exit(0);
      break;
  }
  this.Close();
}

但没有任何反应。

感谢名单

1 个答案:

答案 0 :(得分:1)

将您的代码更改为

case "BTEXIT":
      string strError;
      this.btShow.Content = "Serializing";
      this.btExit.Content = "Please wait";
      Dispatcher.Invoke((Action)(() => { }), DispatcherPriority.Render);
      this.UpdateLayout();
      Serializers.Logger.WriteLog_Reflection<PCDmisLogEntry>;
      System.Threading.Thread.Sleep(2000);
      Environment.Exit(0);
      break;
相关问题