Path to xaml resource file

M

moondaddy

I have a user control located in the following path:

projectFolder/PropertyControls/myControl.xaml

and in myControl.xaml I have a reference to a resource dictionary like this:

<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="Resources/ControlResourceDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>

However this doesn't compile because ControlResourceDictionary.xaml is
located under the main project folder like this:

projectFolder/Resources/ControlResourceDictionary.xaml

What's the correct way to show this path in myControl.xaml?

Thanks.
 
M

Marco Zhou [MSFT]

Hello,

Welcome to Microsoft Newsgroup Support Service! My name is Marco Zhou. It's
my pleasure to work with you on this thread.
If I understand you correctly, you have a UserControl which resides in
"PropertyControls" subfolder under the current project, and inside this
UserControl, you need to merge a resource dictionary file which resides in
another subfolder say "Resources". If this is the case, there are two
options you could try:
First option:
If the current project is a custom control library, you could use the
following the pack URI syntax to refer to the resource dictionary file:
Assemblyname;component/Resources/ControlResourceDictionary.xaml

"Assemblyname" is the name of the assembly which is built from the current
project. For instance, if your project name is "MyCustomControlLib", then
you could name the assembly as "MyCustomControlLib", so the pack URI will
be:
MyCustomControlLib;component/Resources/ControlResourceDictionary.xaml

Second option:
If the current project is a WPF executable project, you could use the
following pack URI instead:
pack://application:,,,/Resources/ControlResourceDictionary.xaml

For more information on pack URI scheme, you could refer to the following
link:
http://msdn.microsoft.com/en-us/library/aa970069.aspx

If you continue having any further questions on this issue, free feel to
ask here, we are glad to answer them.

--------------------------------------------------
Best regards,
Macro Zhou ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

Alun Harford

moondaddy said:
I have a user control located in the following path:

projectFolder/PropertyControls/myControl.xaml

and in myControl.xaml I have a reference to a resource dictionary like this:

<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="Resources/ControlResourceDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>

However this doesn't compile because ControlResourceDictionary.xaml is
located under the main project folder like this:

projectFolder/Resources/ControlResourceDictionary.xaml

What's the correct way to show this path in myControl.xaml?


<ResourceDictionary Source="../Resources/ControlResourceDictionary.xaml"/>

Alun Harford
 
M

moondaddy

Thanks Marco,

To make your suggestion work, I had to use the following syntax:

<ResourceDictionary
Source="pack://application:,,,/UIControls;component/Resources/ControlResourceDictionary.xaml"/>

where UIControls is the assembly name. Alun's suggestion also worked with
the following syntax:

<ResourceDictionary Source="../Resources/ControlResourceDictionary.xaml"/>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top