我有一个 WPF 应用程序,单击按钮后,该应用程序会进入一个可能需要 4-10 秒的计算。我想在该操作期间更新背景的不透明度并显示进度条。
为此,我使用以下代码:
this.Cursor = System.Windows.Input.Cursors.Wait;
// grey-out the main window
SolidColorBrush brush1 = new SolidColorBrush(Colors.Black);
brush1.Opacity = 0.65;
b1 = LogicalTreeHelper.FindLogicalNode(this, "border1") as Border;
b1.Opacity = 0.7;
b1.Background = brush1;
// long running computation happens here ....
// show a modal dialog to confirm results here
// restore background and opacity here.
当我运行代码时,在模态对话框出现之前,背景和不透明度不会改变。在计算开始之前,我怎样才能让这些视觉变化立即发生?我记得,在 Windows 窗体中,每个控件都有一个 Update() 方法,根据需要执行此操作。什么是 WPF 模拟?