How to share ResourceDictionaries in composite WPF Application? - wpf

Have build composite WPF App with Unity Ioc (without Prism).
All my resources (Styles, Templates, Pics) stored in one module (Infrastructure) and merged in Shell-module's App.xaml.
In other modules I use it as StaticResource. Everything works fine when I start the project, but in VisualStudio Designer I can't see my Styles: 'the resource xyz could not be resolved'.
How should I configure VS to see all resources also in designtime?
Possible Solutions:
I could merge everything in each module, but then each resource would be loaded multiple. I could also write my own ResourceDictionary implementation (like: here), but I used to merge resources anyway everywhere - I would avoid this.
I have found a Prism reference solution for a composite application. I don't know how, but there it works without custom ResourceDictionary and without merging it in each module. VS Designer shows everything, although XAML Editor still says "the resource xyz could not be resolved"
Question: is it a feature of Prism? Or there is some configuration hidden?

Solution is simple (has nothing with Prism to do).
All resources should be defined in Shell module (not in Infrastructure module).
Then all modules should be referenced in Shell module project.
No need to merge resources in each module.
Each module knows only high level modules, and only shell knows everyone.

Related

How to use MEF with WPF

Is there a way to create a product (Software) divided in modules?
What I mean is for example create an application using WPF that is divided in 3 modules (in the future they may be more) Main Module, Module 1, Module 2
Each module could be a standalone solution. Each of them with presentation, Business and Data access layers.
From the Main Module when a button is clicked, it will call any other module for example module 1 but the UI of the module should be seen like if it were from the main Module.
I have manage to use MEF to separate project building but I don now how to use MEF with WPF
Any Starting point or suggestion?
Putting your business and data access layers in a MEF module is fairly straightforward and accomplished as you would for any other project, the trick with WPF is adding the view resources. That can be done by putting them in a ResourceDictionary decorated with the Export attribute and merged into the global dictionary, as shown in the answer to "How to provide XAML resources from MEF components".

Applying global styles to inherited Windows controls in control library

I'm a complete n00b to WPF but I'm working on my first application. I already realize that styles I use in the application I will likely want to use in future applications, so I'd like to use some method of applying global styles from project to project.
I've seen plenty of tutorials on creating a control library project, but they all go into creating custom controls. I don't really need custom controls (yet) per se, just the standard Windows controls with custom styles.
I'm also a little unclear on the whole ResourceDictionary thing. I've found examples on creating one for an application project, but not so much for a control library project.
What I'm looking for here is a) is a control library really what I need or am I creating more work than necessary? b) am I on the right path with a ResourceDictionary? and c) any good links to tutorials/examples that might go into what I'm trying to do rather than just a custom control creation tutorial.
You definitely want a ResourceDictionary with styles that you will be using in other apps. You can then reference it on an application, window, or even control level by including it in the application, window or control resources.
Where you put that resource dictionary isn't that important, though a custom control project is a common place to do so. It can be anywhere, in any project, and you can reference it with a URI.
Microsoft has a pretty good writeup on resources: Using Resources. Here's a decent tutorial on using dictionaries: Resource Dictionaries
You are in the right direction with ResourceDictionary. Create one for your application in a separate library move all your Styles there and refer them using Pack URI syntax. Here is a related question: ResourceDictionary in a separate assembly

PRISM Sharing styles between modules

I'm testing the reference project that karl has made for silverlight.
In it on of the modules have a StaticResource binding to a resource that is in the App.xaml file.
When i do the same the design view does not show the style in my module.
What am i missing?
Common contains Styles.xaml
Shell merges Styles.xaml
ModuleA {StaticResource StyleA}
This is a problem of the design tool. I suppose that the assembly of ModuleA is not referenced by the Shell, right? Then the tool has no reason to know that ModuleA will be loaded only when the Shell is loaded. I doesn't know that these projects are related, hence it doesn't look for styles in the Shell project when it loads a view from ModuleA in the designer.
One solution would be to reference the shared styles dictionary in every view of ModuleA that you want to open in the designer, but this is not a very good solution as it is a code duplication. Another solution, if you are using Expression Blend, might be to use design-time dictionaries, but I don't know if there is something like this for Visual Studio designer.
I can across the same problem. I've seen some Prism applications a "Common" project to define things like "Region Names" constants and etc. If the all the styles were defined there that might be a better solution. That way each module could reference these styles or create thier module specific styes.

IlMerge Silverlight Class Library with Custom Controls

I am trying to merge all the assemblies of an class library in a single .dll file.
I can merge all the assemblies using the Ilmerge but is that when I use the merged dll in a Silverlight application I am having trouble when a template is apply to my control and binding problems if I use a control that inherits with UserControl.
is there any solution to solve this problem?
The problem is that when the initial dlls are built the Xaml in the project is added as a resource in the dll. The code generated to load this xaml will look something like this:-
System.Windows.Application.LoadComponent(this, new System.Uri("/SilverlightLibrary1;component/MyControl.xaml", System.UriKind.Relative));
Note how the name of the dll forms part of the Uri need to fetch the xaml. I doubt IlMerge is able to spot that and fix it up. Hence once merged the Uris cannot be found.
A resolution for this is probably uglier than multiple references or simply creating another project that links all the code files involved.

Resources for both WPF and Silverlight in the same assembly

I have resources in separate assemblies to be used by multiple WPF apps and this is working fine. Now I am creating a Silverlight 3 app and am trying to use the same assembly to get the same resources. I get an error at the time of adding a reference, saying only Silverlight assemblies can be referenced.
What's the best way for me to do this? Must I have 2 separate sets of assemblies for resources - one for WPF and one for Silverlight? I would not like to maintain two distinct but identical resource assemblies...
Thanks
Note: "link-adding" a file resolved the issue of sharing the same xaml across multiple assemblies. However, to me, one major drawback is that this feature is not supported in Blend 3! Blend keeps trying to find the file locally in the project tree.
Unfortunately, .NET assemblies cannot be referenced from a Silverlight app.
For details and possible solutions, see http://www.pagebrooks.com/archive/2008/10/11/sharing-code-between-.net-and-silverlight-platforms.aspx.
Can you store the resources externally and then use a pre-build step to copy the files into a silverlight assembly that you reference in your project? That was you can avoid having duplicate assemblies and just change the resources in a single location.

Resources