VSTO Office(Excel)加载项 – WPF XAML样式,ResourceDictionary
我想用Windows安装程序部署我的VSTO Office Excel加载项。 我创build了安装程序并在虚拟PC上安装了加载项,以对其进行testing。 现在我有问题,风格不工作,但如果我debugging或在Visual Studio中运行它确实工作。
例如,我创build了一个这样的样式:
<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>
它只能在安装后才起作用,当我使用“样式”的“键”并将“样式”直接设置为“控件”时。
我认为Source属性中的URI是问题所在。 尝试使用Pack URI
你如何储存你的资源? 发布xaml,以及你使用的包uri – HighCore
这是带有样式(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,我尝试使用:
这些工作时,我debugging/使用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" />