1

I'm developing a bunch of custom activity designers, which contain custom controls, images, styles etc. The designer XAMLs are spread over several subdirectories in a library project (not a WPF application, therefore no app.xaml available)

I need a central place to store resources, just like the app.xaml in a regular WPF application.

Currently I use a projectdir\Properties\lib.xaml file like this:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<ControlTemplate x:Key="TrafficLight">
 ...
</ControlTemplate>
</ResourceDictionary>

And reference this from all my designer XAMLs like this:

<sap:ActivityDesigner.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/ActDesLib;component/Properties/lib.xaml" />
        </ResourceDictionary.MergedDictionaries>

where ActDesLib is the name of my assembly.

This does work, but it looks a bit clumsy. Is there a better way to do it?

Is there some "magic" app.xaml-like file that gets included automatically for a library project, without the need to add any special markup to the individual XAML files? That would make it so much easier to enforce a consistent style, even with multiple developers working on the different designers.

BTW: I tried to use relative pathes in the Source="..." attribute. This did not work when using my activities in a workflow inside VS2010, it could not find the resources then. With the absolute path, containing assembly name, it works fine. But is there no way that VS2010 or a rehosted designer can find out the path to the resource dictionary file automatically, with only relative references inside my XAMLs?

Achim
  • 828
  • 6
  • 21
  • In your local assembly you could create a shared resources dictionary and perform merging there. That way you can use a relative path to this resource dictionary. No big gain there. AFAIK, there is no magic way, and you have to use the absolute path so that the xaml reader can load the assembly from disk. –  Apr 06 '13 at 21:33
  • Thanks, at least that shows I'm not on the completely wrong track. After diggin a bit deeper, I'm wondering if that Themes\generic.xaml could help here. Does that theming stuff work for ActivityDesigner libs (after all, they are just WPF)? – Achim Apr 07 '13 at 19:06
  • Absolutely. You probably could do your dictionary merge within the generic.xaml resource dictionary, and that would automatically be loaded in the VS designer... –  Apr 07 '13 at 21:30
  • I tried that, but it didn't work. I guess I did overestimate the power of generic.xaml. It seems to have its magic only for the default style for custom controls. But resources defined in it are NOT automatically available for other controls. I thought it would be possible e.g. to define a style to have all ExpressionTextBoxes a margin of 3, and that would be picked up in all ActivityDesigners, without any explicit dictionary merge in the designer xaml. That's obviously not the case. Even named styles from the generic.xaml can not be found with {StaticResource...}. Would have been so nice... – Achim Apr 08 '13 at 20:15
  • I actually think it should be possible, but defining WPF *themes* in your assemblies is **not** straightforward. Have you ever done this successfully before? You have to do a few (poorly documented and seemingly random) things before it all hooks up. I'm short on time today or I'd spin up a POC to see if I can answer. Lemme see if I can take some time during lunch tomorrow and get it to work. But please let me know if you've ever successfully created your own WPF theme, as if you have then you might be right... –  Apr 08 '13 at 20:26
  • @Will Unfortunately the answer is no. Never used the themes features before :( There has never been a good reason in my previous projects. Anyway, I don't want yopu to spend your time on that. It would have been a nice and clean way, without bothering our other activity designer developers, but of course I can ask all of them to do the dictionary merge manually in their XAMLs. (Currently we have ~170 activities in our project) – Achim Apr 09 '13 at 06:30

0 Answers0