3

Due to the nature of my solution (modules being loaded at run time) I get "resource could not be resolved" errors for all of the resources defined in the plugged in modules. The application works, but the many error messages in the XAML and the false errors in the debug window are problematic.

I could add the dictionary where the resources are defined to each of my UserControls manually but that is less then ideal. Normally the dictionary would be added in app.xaml but my plugins don't have an app.xaml.

Is there a way to suppress these warnings?

Cœur
  • 37,241
  • 25
  • 195
  • 267
user1604008
  • 995
  • 9
  • 17
  • Please show some XAML examples. – Sheridan Jun 20 '14 at 23:11
  • Not sure what I could show you. Maybe I'm not being clear. Project A is a wpf application. It references project B. Project B is not a wpf application nor is it a user control. neither Generic.xaml nor App.xaml is available. How can all of the controls in Project B inherit shared resources? – user1604008 Jun 20 '14 at 23:20
  • 1
    You want to share WPF `Resources` with a non WPF Application? What kind of project is it? Also, your description of *many error messages in the XAML* is really not that helpful. If you want some real help, you'll have to explain your whole situation a lot clearer. What error messages and where are they showing? What false errors? What are these plugins? – Sheridan Jun 20 '14 at 23:26
  • Yes, it is a class library. The many error messages is one for all of the StaticResources that are referenced in that application. The designer can not find the resources as they are defined in a resource dictionary local to the class library, they can however be found at run time. They can be found at run time because Project A loads Project B at run time, then loads Project B's resource dictionary into Application.Resources. In this example Project B is what I'm calling the plugin. The error messages are in the output window at design time, although it builds and runs succesfully. – user1604008 Jun 21 '14 at 02:04
  • Perhaps I'm misunderstanding something, but that sounds like a mess. Why put UI resources into a class library? Just put things where they belong and you should find that things start to work properly again. – Sheridan Jun 23 '14 at 08:23

2 Answers2

0

I am assuming you are talking about errors instead of warnings since you mentioned debug window. There is partial workaround: using DynamicResource instead of StaticResource will make such styles appear as warnings instead of errors in the Error List window. However, xaml source code will still be underlined. Guess a bad solution is better than no solution.

wondra
  • 3,271
  • 3
  • 29
  • 48
0

Check out Trick To Use A ResourceDictionary Only When In Design Mode

The ideal architecture is to create an intermediate infrastructure library containing your resource dictionary. The main application would then load the styles in app.xaml referring to this infrastructure library. Your "Project B" (class library/plugin/module) can use the DesignTimeResourceDictionary to avoid any errors/warnings at design time. At run time the resources will be fetched based on application and the DesignTimeResourceDictionary would be skipped.

Check out this answer too: Avoiding Visual Studio designer errors when WPF resource is defined in separate project

Sahil Shah
  • 95
  • 6