[英]Setting visibility and activity of a component in a callback
I have a WPF program with a callback that executes after an async method. 我有一个WPF程序,带有一个在异步方法后执行的回调。
The callback looks like this: 回调看起来像这样:
public void ProcessCompleteCallback()
{
MessageBox.Show("Process completed.");
GenerateOutputButton.IsEnabled = true;
LoadingGifImage.Visibility = Visibility.Hidden;
CommandManager.InvalidateRequerySuggested();
}
The first line get executed, but there's no change in the GUI regarding the second and third lines. 第一行被执行,但是GUI中第二行和第三行没有变化。 I tried to force a Requery by invoking the CommandManager, but it does not help. 我试图通过调用CommandManager来强制执行Requery,但这无济于事。
Any idea why it isn't working? 知道为什么它不起作用吗?
Try this: 尝试这个:
public void ProcessCompleteCallback()
{
MessageBox.Show("Process completed.");
Application.Current.Dispatcher.Invoke(() =>
{
GenerateOutputButton.IsEnabled = true;
LoadingGifImage.Visibility = Visibility.Hidden;
CommandManager.InvalidateRequerySuggested();
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.