Does XAML work with file links in Visual Studio?

Posted by Tim on Stack Overflow See other posts from Stack Overflow or by Tim
Published on 2010-04-20T18:22:34Z Indexed on 2010/04/20 18:53 UTC
Read the original article Hit count: 244

Filed under:
|
|
|

I'm adding a new WPF project to an existing Visual Studio solution and would like to reuse a bunch of code (C# and xaml) from an existing project within the solution.

I've created the new project and added existing files as follows:

  • Right click project
  • Add -> Add Existing Item
  • Find the file to reuse, use the arrow next to "Add" and "Add as Link"

I now have a nice project set up with all the proper links. However, XAML chokes on these links. For example:

<ResourceDictionary.MergedDictionaries>
       <ResourceDictionary
           Source="Resources\Elements\Buttons\Buttons.xaml" />
       <ResourceDictionary
           Source="Resources\Elements\TextBox\TextBox.xaml" />
 </ResourceDictionary.MergedDictionaries>

The files "Buttons.xaml" and "TextBox.xaml" exist as links in my new project. The project builds, but when I run, I get the following XamlParseException:

'Resources\Elements\Buttons\Buttons.xaml' value cannot be assigned to property 'Source' of object 'System.Windows.ResourceDictionary'. Cannot locate resource 'resources/elements/buttons/buttons.xaml'.

It seems like the XAML parser is requiring an actual copy of these XAML files to exist in my new project, instead of links.

This is exactly what I'm trying to avoid. I want my project to share these files so that any changes get transferred to the other project without hunting and copying.

Any insight is appreciated!

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf