Problem
I'm trying to detect and close an opened WPF dialog box in PowerPoint using a VSTO addin. When I use the solution from this question, it doesn't seem to work because System.Windows.Application.Current
always return null eventhough there is a dialog box opened.
Code
Instead of using the default Winform as dialog box, my dialog box is a WPF Window, e.g.,
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
x:Name="Test"
WindowStyle="None"
SizeToContent="WidthAndHeight">
...
</Window>
This is the code-behind:
namespace AddInProject.Classes
{
public partial class DlgCustomWindow:Window, IDisposable
{
public CustomWindow()
{
InitializeComponent();
}
public Dispose()
{
this.Close();
}
}
}
I use this method to open the WPF window above
using (DlgCustomWindow dlgCustom = new DlgCustomWindow())
{
dlgCustom.ShowDialog();
}
But running System.Windows.Application.Current
always return null.