5

I have a resource dictionary in an external assembly, which I have merged in my app.xaml, like so:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/My.Library;component/Theme.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

I wish to reference said resources using StaticResource bindings.

I am getting design-time errors in Visual Studio 2013 stating the resources do not exist. I am not getting any compiler errors though, and the resources do show up fine at run-time.

I have read posts about problems with the VS Designer not showing external resources properly, but I don't use the Designer and that is not what my question is about. I am getting errors in the error window stating the resources cannot be resolved, and I've got a serious case of the squigglies. I have tried a full clean and rebuild.

Again, everything compiles and runs fine, but this is not very convenient since I now have to sift through the error list to see what are actual errors and what is simply Visual Studio not resolving the referenced resources correctly.

For grins I did try switching to DynamicResource, and indeed the error went away. However, these resources will not be changing during the application lifetime and I do not wish to incur all of the extra overhead just to solve a problem with the IDE.

Does anybody know a proper fix for this?

amnesia
  • 1,956
  • 2
  • 18
  • 36
  • You're putting a resource Dictionary into the program's resources & then trying to reference resources in it? Sorry, I think you need to use a DynamicResource reference, and I'm not sure that's gonna work, either. I've never done anything like that myself so I don't know. – Tony Vitabile Sep 03 '14 at 16:43
  • @TonyVitabile It does work, I'm just getting errors in the IDE. – amnesia Sep 03 '14 at 16:45
  • take a look at this question: http://stackoverflow.com/questions/1088762/avoiding-visual-studio-designer-errors-when-wpf-resource-is-defined-in-separate – sexta13 Sep 03 '14 at 16:49
  • @sexta13 The accepted answer for that post is to switch to DynamicResource, which I explained I didn't see as a viable solution. – amnesia Sep 03 '14 at 17:06
  • and the answer that has more votes? – sexta13 Sep 03 '14 at 17:07
  • @sexta13 It's even worse, it involves mocking out all resources into a custom resource dictionary that only loads at design-time and then including it on all of our views to prevent the errors. Creative, but highly impractical. – amnesia Sep 03 '14 at 17:10
  • one last question, why dynamic is not a viable solution? – sexta13 Sep 03 '14 at 17:14
  • 1
    @sexta13 Dynamic causes the resource to be looked up every time it is accessed (potentially a lot), the purpose is for resources that might change during runtime, like a user-selectable brush color. I don't want the performance penalty, especially just to hack around a problem with the IDE. – amnesia Sep 03 '14 at 17:26
  • fair enough...i agree with you – sexta13 Sep 03 '14 at 21:10
  • Same problem here, this was working just fine in VS2010 – Fredrik Hedblad Oct 29 '14 at 08:21

0 Answers0