Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

Commented Unassigned: MessageBox not displayed when owner is null. [21039]

$
0
0
MessageBox.ComputeOwnerWindow() method checks whether one of the windows in the current application is active. If foreground window is different than the application window MessageBox not displayed correctly and makes the application window inaccessible. I did not test but IMHO ComputeOwnerWindow() method can fallback to Application.Current.MainWindow.
Comments: ** Comment from web user: noderino **

I can not provide a sample because it is not happening every time i call MessageBox.Show(). But i can give you more detail. I am using a WCF service with async calls. Some methods take about 1 minute. during this time i change foreground window to something else for example notepad. ComputeOwnerWindow method checks whether one of the windows in the application is activated. Actualy it is not because foreground window is set to notepad window and ComputeOwnerWindow returns null. If owner is null message window show in screen center. I think this is a multi monitor problem. When i set the owner in MessageBox.Show it works normally (tested over 3 days).

with IMHO, i wanted to say "in my opinion".

This should work.
```
private static Window ComputeOwnerWindow()
{
Window owner = null;
if( Application.Current != null )
{
owner = Application.Current.MainWindow;
foreach( Window w in Application.Current.Windows )
{
if( w.IsActive )
{
owner = w;
break;
}
}
}
return owner;
}
```


Viewing all articles
Browse latest Browse all 4964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>