I have am creating a WPF extension to an existing Win32 MFC client application. Within a UserControl located in my WPF class library, I am merging libraries as follows:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="MyResourceDLL;Component/dictionaries/styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
I also tried
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MyResourceDLL;Component/dictionaries/styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
In either case, I get the following XamlParseException:
System.Windows.Markup.开发者_如何学JAVAXamlParseException occurred
Message="MyResourceDLL;Component/dictionaries/styles.xaml' value cannot be assigned to property 'Source' of object 'System.Windows.ResourceDictionary'. Cannot locate resource 'ems.wpf.resources;component/dictionaries/styles.xaml'. Error at object 'System.Windows.ResourceDictionary' in markup file 'SARMaster.Maryln.EphemerisLib;component/getephemeriscontrol.xaml' Line 9 Position 37."
I there a way I can load a relative DLL that is not referenced by main project?
I've been looking at the same issue recently. When compiling a Win32 CLR project the dependencies of the assemblies referenced by the MFC project aren't copied, so I simply set up a post-build event to copy the appropriate assemblies to the $(TargetDir).
Not ideal, but I believe it's by design.
I got the same problem and I found the solution. I needed to remove the Style of my ContentPresenter. This line was creating the XamlParseException:
<ContentPresenter.Resources>
<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource TextStyle}"/>
</ContentPresenter.Resources>
And after fixing this error, I needed to do these steps to have something 100% working:
Here my projects:
- StyleProject: the
Class Library
project that I want to use. It contains my styles - MainProject: the project that will use the styles
To do so:
- Add the reference of my StyleProject inside my MainProject (see here)
- Create a
ResourceDictionary
called MyStyle.xaml inside my MainProject - Add the different dictionaries of my StyleProject following this answer to MyStyle.xaml
- Add MyStyle.xaml to the App.xaml using the following code
Code:
<ResourceDictionary Source="Resources/MyStyle.xaml"/>
精彩评论