VSTO Office(Excel)加载项 – WPF XAML样式,ResourceDictionary

我想使用
Windows Installer部署我的VSTO Office Excel-Add-In.

我创建了安装程序并在虚拟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>

它仅适用于安装后,当我使用样式的键并将样式直接设置为控件时.

这是带有样式(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>

这里是“Merge”-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" />

最佳答案 我认为Source属性中的uri是问题所在.尝试使用
Pack URIs

点赞