wpf - VSTO Office (Excel) 加载项 - WPF XAML 样式、ResourceDictionary

标签 wpf excel windows-installer vsto

我想使用 Windows 安装程序部署我的 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 合并到窗口资源,我尝试使用:

这些在我使用 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

关于wpf - VSTO Office (Excel) 加载项 - WPF XAML 样式、ResourceDictionary,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13159722/

相关文章:

c# - 当绑定(bind)到 WPF DataGrid 时,此 View 不允许使用 DataGrid 版本 'EditItem'

c# - 查找 IEnumerable 的第一个索引

excel - 检查 Excel 中是否存在损坏的超链接

vba - 如何使用工作表函数过滤数组?

visual-studio - wix安装程序更改生成目录名称

c# - 使用 InstallShield 创建的安装 Exe 文件无法成功安装 Outlook 插件

c# - 从鼠标光标在屏幕上的位置获取图像坐标(WPF 图像控件)

c# - WPF Combobox Itemssource 是 Visibility Enum

c# - Windows 窗体是否有类似 Snoop (WPF) 或 FireBug (ASP.NET) 之类的东西?

Wix MajorUpgrade问题