【发布时间】:2012-10-31 14:00:02
【问题描述】:
我想使用 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(其中包含样式)与 Window 的 ResourceDictionary 合并:
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/assembly;component/UI/Resources/Style.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
它只在设置之后才起作用,当我使用样式的键并将样式直接设置为控件时。
这是带有样式的 ResourceDictionary (Styles.xaml):
<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" />
【问题讨论】:
标签: wpf excel windows-installer vsto