简体   繁体   中英

UI not getting updated after call to OpenFileDialog.ShowDialog()

I have a WPF Application consisting of a MainWindow which also has a regular button inside. Bound to the button click event I am loading a serialized object via OpenFileDialog:

private void LoadNetwork_Click(object sender, RoutedEventArgs e)
{
    var openDialog = new OpenFileDialog { Multiselect = false };
    var result = openDialog.ShowDialog();
    if (result)
    {
        string file = openDialog.FileName;
        try
        {
             _network= new SimplifiedNetwork(file, 1);
             MessageBox.Show("Loaded OK");
        }
        catch (Exception)
        {
             MessageBox.Show("Load error");
        }
    }
}

After this method gets executed the UI doesn't update anymore. And when I say nothing, I mean not even the hover effects on the buttons in the Window work (not to mention updating labels via code behind, property changed events, begin invokes etc.), it's like it's frozen (but still responsive to clicks).

I thought it was something I did inside my routines, but simply reducing the method call to

private void LoadNetwork_Click(object sender, RoutedEventArgs e)
{
    var openDialog = new OpenFileDialog { Multiselect = false };
    var result = openDialog.ShowDialog();  
}

has the same result.

Clarification. -This occurs with after the Modal dialog is closed. -It also seems to manifest itself as soon as the UI loses focus for any reason (like minimize - restore, switch to another window). -This seems to occur only on my Windows 8.1 machine (put in an xp VM I have around, is OK).

Any ideas?

The OpenFileDialog is a modal dialog, it is intended that the window in the background is not responding when the dialog is open.

Here is more information and also a possible solution to your problem.

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