Exposing resources from specific XAML files globally (WPF)

I'd like to create a small R# extension that finds all resources in a specific (App.xaml) XAML file's ResourceDictionary and makes them available for all other XAML files to work with.

This is something that R# currently doesn't do right, as it doesn't seem to understand that resources from App.xaml are available in the global 'scope' and can be used by all other XAML files in that project, resulting in a lot of underlined StaticResource/DynamicResource references.

The thing is that I have no experience in creating R# plugins, so I don't know what the approach should be here, what's the best way to tackle this? Which parts of the documentation should I read? Is it even possible to do this?

Thanks.

Edit: it seems this has already been fixed in 8.2, so it's no longer needed.

3 comments
Comment actions Permalink

It seems my edit was too soon, R# doesn't seem to resolve references to the global resources anymore. So I guess I still have to create the plugin.

0
Comment actions Permalink

Hi,

It's not possible to easily integrate into resource resolution process with a plugin.
We can resolve resource references from App.xaml files, but only when project
where resource is references directly or indirectly references project with App.xaml file.

We doesn't do 'backward' resolve, so, for example, we do not search prjoects,
referenceing current one (with resource reference) and maybe providing App.xaml files,
because there may be multiple projects, with resources of different types and so on.

Can you please clarify the scenario we do not support in your case? Maybe, provide some sample solution?

Thanks!

0
Comment actions Permalink

Then I guess this is currently working by design, but it seems odd to completely ignore App.xaml in other projects when in fact the very purpose of this file is to provide app-scoped resources.

I think many solutions have a project structure something like the following:

Main (exe): has App.xaml
Module 1 (dll): referenced by Main
Module 2 (dll): referenced by Module 1
Module 3 (dll): referenced by Main and Module 2
...
Module n...


It's common to include all WPF resources only in the Main project for optimization (prevent multiple parsing, loading, memory usage etc.) and centralization. The modules can then use the resources from Main's App.xaml without explicitly including App.xaml.

So perhaps you could search the App.xaml from the main executable project and include the resources defined in that file in the global scope of the modules included by that Main project.

This can provide false positives when the modules are loaded and executed in an environment where Main.exe isn't available (e.g. when used by some other application), but perhaps you can let users specify whether to use App.xaml or not to work around this.

Edit: see also:
http://youtrack.jetbrains.com/issue/RSRP-274698
http://youtrack.jetbrains.com/issue/RSRP-388490
http://youtrack.jetbrains.com/issue/RSRP-335074

0

Please sign in to leave a comment.