[英]Making XAML Designer load ResourceDictionary from file in WPF hosted app
I have a WinForms project which uses hosted WPF controls . 我有一个使用托管WPF控件的WinForms项目。 I have a resource dictionary saved in my Resources which I load into my Application object at runtime using the following code placed before System.Windows.Forms.Application.Run() :
我有一个资源字典保存在我的资源中,使用在System.Windows.Forms.Application.Run()之前的以下代码在运行时将其加载到Application对象中:
new System.Windows.Application();
System.Windows.Application.Current.Resources.MergedDictionaries.Add(
System.Windows.Application.LoadComponent(
new Uri("/MyApp;component/Resources/Styles.xaml",
UriKind.Relative)) as System.Windows.ResourceDictionary);
Which works fine in the end application, but the problem is, as it is loaded at the runtime, that file is not loaded by the Designer. 在最终应用程序中可以正常工作,但是问题在于,由于它是在运行时加载的,因此设计器无法加载该文件。 Is there a way to make the XAML Designer load this file in my control (at least for UI building purposes)?
有没有办法让XAML设计器在我的控件中加载此文件(至少出于UI构建的目的)?
Okay, I got this. 好吧,我明白了。 You can load ResourceDictionary from within the xaml with the following code:
您可以使用以下代码从xaml中加载ResourceDictionary:
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/MyApp;component/Resources/Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
Just delete this after designing the control to keep things clean. 在设计控件以保持环境干净之后,只需删除此内容即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.