public void Progress_Close(Window oWindow, Window owner = null)
{
try
{
Application.Current.Dispatcher.Invoke(new Action(() =>
{
Window wndParent = owner;
try
{
if (wndParent == null)
{
wndParent = Application.Current.MainWindow;
}
if (wndParent != null)
{
{
wndParent.Opacity = 1;
wndParent.Effect = null;
}
}
if (oWindow.Visibility != Visibility.Visible)
return;
if (!oWindow.IsVisible)
{
return;
}
if (oWindow == null || !oWindow.IsVisible)
return;
oWindow.Hide();
}
catch (Exception ex)
{
}
}));
}
catch (Exception ex)
{
cGlobalSettings.oLogger.WriteLogException("Progress_Close:: ", ex);
}
}
public void Progress_Show(Window oWindow, Window owner = null, bool showAsDialog = true)
{
try
{
if (oWindow == null)
{
return;
}
this.Dispatcher.Invoke(new Action(() =>
{
try
{
if (owner == null)
{
owner = Application.Current.MainWindow;
}
owner.Opacity = 0.2;
owner.Effect = new System.Windows.Media.Effects.BlurEffect();
oWindow.ShowInTaskbar = false;
oWindow.Owner = owner;
oWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;
{
oWindow.Left = Application.Current.MainWindow.Left + (this.ActualWidth - oWindow.ActualWidth) / 2;
oWindow.Top = Application.Current.MainWindow.Top + (this.ActualHeight - oWindow.ActualHeight) / 2;
}
if (showAsDialog)
oWindow.ShowDialog();
else
{
oWindow.Show();
}
}
catch (Exception ex)
{
}
finally
{
if (owner != null)
{
if (showAsDialog && !(owner == Application.Current.MainWindow ))
{
owner.Opacity = 1;
owner.Effect = null;
owner.Activate();
}
}
}
}));
}
catch (Exception ex)
{
cGlobalSettings.oLogger.WriteLogException("Progress_Show:: ", ex);
}
}
and call above function like this
private void LoadAboutForm()
{
try
{
this.Dispatcher.Invoke(new Action(() =>
{
ofrmAbout = new frmAbout();
ofrmAbout.OnCloseWindow += OfrmAbout_OnCloseWindow;
Progress_Show(ofrmAbout, Application.Current.MainWindow, true);
}));
}
catch (Exception ex)
{
cGlobalSettings.oLogger.WriteLogException("MainUserControl.xaml.cs|TabItem_MouseUp()", ex);
}
}
private void OfrmAbout_OnCloseWindow()
{
if (ofrmAbout != null)
{
Progress_Close(ofrmAbout, Application.Current.MainWindow);
}
}