我想使用 Windows Installer 部署我的 VSTO Office Excel 加载项。我创建了安装程序并在虚拟 PC 上安装了加载项,以对其进行测试。现在我遇到了问题,样式不起作用,但是如果我在 Visual Studio 中调试或运行它,它确实可以工作。
例如,我创建了这样的样式:
<Style TargetType="{x:Type Button}">
<Style.Setters>
<Setter Property="Background" Value="Snow" />
<Setter Property="Width" Value="50" />
<Setter Property="Height" Value="25" />
<Setter Property="Margin" Value="5" />
</Style.Setters>
</Style>
现在我将 ResourceDictionary(其中包含样式)与窗口的 ResourceDictionary 合并:
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/assembly;component/UI/Resources/Style.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
它仅在设置后才有效,当我使用样式的键并将样式直接设置为控件时。
这是带有样式 (Styles.xaml) 的 ResourceDictionary:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="{x:Type Button}">
<Style.Setters>
<Setter Property="Background" Value="Snow" />
<Setter Property="Width" Value="50" />
<Setter Property="Height" Value="25" />
<Setter Property="Margin" Value="5" />
</Style.Setters>
</Style>
</ResourceDictionary>
这是“合并”-ResourceDictionary:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/ExcelAddIn;component/UI/Resources/Style/Brushes.xaml" />
<ResourceDictionary Source="/ExcelAddIn;component/UI/Resources/Style/ControlTemplates.xaml" />
<ResourceDictionary Source="/ExcelAddIn;component/UI/Resources/Style/Styles.xaml" />
<ResourceDictionary Source="/ExcelAddIn;component/UI/Resources/Style/DataTemplates.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
要将 ResourceDictionary 合并到 Window-Resources,我尝试使用:
这些在我使用 Visual Studio 调试/运行它时工作,但在安装后不工作:
<ResourceDictionary Source="/ExcelAddIn;component/UI/Resources/Style/Skin.xaml" />
<ResourceDictionary Source="pack://application:,,,/ExcelAddIn;component/UI/Resources/Style/Skin.xaml" />
<ResourceDictionary Source="pack://application:,,,/ExcelAddIn;v1.0.0.0;component/UI/Resources/Style/Skin.xaml" />
这些通常不起作用:
<ResourceDictionary Source="pack://application:,,,/UI/Resources/Style/Skin.xaml" />
<ResourceDictionary Source="/UI/Resources/Style/Skin.xaml" />