简体   繁体   中英

Setting visibility and activity of a component in a callback

I have a WPF program with a callback that executes after an async method.

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. I tried to force a Requery by invoking the CommandManager, but it does not help.

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();
    });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM