我使用WPF窗口为Excel创建了Addins VSTO。一切正常。不幸的是,当我附加WindowChrome窗口样式时,关闭Excel后出现System.AppDomainUnloadedException错误。
我有一个Excel 2016,Visual Studio 2017,Net Framework 4.6.1。
这是Window1的代码:
<Window x:Class="ExcelAddIn1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:shell="clr-namespace:Microsoft.Windows.Shell;assembly=Microsoft.Windows.Shell"
xmlns:local="clr-namespace:ExcelAddIn1"
mc:Ignorable="d"
Title="Title" Width="300" Height="300" WindowState="{Binding CurWindowState, Mode=TwoWay}">
<Window.Resources>
<Style x:Key="GStyle" TargetType="{x:Type local:Window1}">
<Setter Property="shell:WindowChrome.WindowChrome">
<Setter.Value>
<shell:WindowChrome
CaptionHeight="36"
GlassFrameThickness="-1"
ResizeBorderThickness="4" />
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:Window1}">
<Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid />
</Window>
这是Window1后面的代码:
using System.Windows;
namespace ExcelAddIn1
{
/// <summary>
/// Logika interakcji dla klasy Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
Loaded += Window_Loaded;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Style _style = null;
if (Microsoft.Windows.Shell.SystemParameters2.Current.IsGlassEnabled == true)
{
_style = (Style)Resources["GStyle"];
}
this.Style = _style;
}
}
}
这是插件的代码的一部分:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
(new Window1()).Show();
}
如何解决此问题?