Excel加载项中的WPF资源字典 [英] WPF Resource Dictionary in Excel Addin
问题描述
我已经搜索了一段时间,但仍未找到解决方案.这是我的情况:
I've been searching a while now and still no closer to a solution. Here's my situation:
我正在创建一个Excel加载项,并希望使用WPF使其看起来更好一些.就本人而言(据我所知),加载项必须是WinForm.我开始使用WPF元素托管,但效果不是很好.然后,我发现将WPF项目添加到解决方案的效果很好,但是现在我想使用资源字典来使表单保持相同并减少内联样式.我只是无法使合并的字典正常工作.
I am creating an Excel Addin and want to use WPF to make it look a little better. Natively (as far as I know) Addins have to be WinForm. I started using WPF Element Hosting but the reult is not very good. I then found that adding a WPF Project to the solution works which is great, but now I want to use a Resource Dictionary to keep forms looking the same and reducing inline styles. I just cant get the merged dictionaries to work.
我尝试了Pack URI和; component/.....,但是都没有用.
I have tried Pack URI and ;component/..... but neither work.
我在做什么错了?
-------编辑-------
-------EDIT-------
我有一个称为SolutionA的Excel加载项解决方案该解决方案包含3个项目:
I have a Excel Addin Solution called SolutionA The solution contains 3 Projects:
ProjectA是一个Excel加载项项目,具有对ProjectB和ProjectC的引用
ProjectA which is an Excel Addin Project which has references to ProjectB and ProjectC
ProjectB是WPF项目,它引用了ProjectC
ProjectB which is a WPF Project which has a reference to ProjectC
包含资源字典的ProjectC
ProjectC which contains the resource dictionary
只需要知道如何从ProjectB引用资源字典
Just need to know how to reference the resource dictionary from ProjectB
推荐答案
我以这种方式使其工作:
I made it work this way:
- 在运行时添加字典
wpfApp = new Application(){ShutdownMode = ShutdownMode.OnExplicitShutdown};wpfApp.Resources.MergedDictionaries.Add(new ResourceDictionary(){Source = new Uri("pack://application:,,,/MahApps.Metro; component/Styles/Controls.xaml")});wpfApp.Resources.MergedDictionaries.Add(new ResourceDictionary(){源=新的Uri("pack://application:,,,/MahApps.Metro; component/Styles/Fonts.xaml")});wpfApp.Resources.MergedDictionaries.Add(new ResourceDictionary(){源=新Uri("pack://application:,,,/MahApps.Metro; component/Styles/Themes/Light.Blue.xaml")});
-
在xaml中使用DynamicResource
use DynamicResource in xaml
< ContentControl Foreground =" {DynamicResource MahApps.Brushes.IdealForeground}"/>
在VS2019中通过net48 vsto excel插件在O365本地安装版本16.0中工作.+
Works in VS2019 with net48 vsto excel addin with O365 local install version 16.0.+
这篇关于Excel加载项中的WPF资源字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!