【发布时间】:2017-10-19 10:37:51
【问题描述】:
问题
我正在尝试使用 VSTO 插件检测并关闭 PowerPoint 中打开的 WPF 对话框。当我使用this question 的解决方案时,它似乎不起作用,因为System.Windows.Application.Current 总是返回null,即使打开了一个对话框。
代码
我的对话框不是使用默认的 Winform 作为对话框,而是 WPF 窗口,例如,
<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>
这是代码隐藏:
namespace AddInProject.Classes
{
public partial class DlgCustomWindow:Window, IDisposable
{
public CustomWindow()
{
InitializeComponent();
}
public Dispose()
{
this.Close();
}
}
}
我用这个方法打开上面的WPF窗口
using (DlgCustomWindow dlgCustom = new DlgCustomWindow())
{
dlgCustom.ShowDialog();
}
但运行 System.Windows.Application.Current 总是返回 null。
【问题讨论】:
标签: c# .net wpf vsto powerpoint