WPF skin library working in Visual Studio 2008 Designer

In our projects, we have views and controls that are in many different assemblies (over 40 assemblies in one solution with 100 viewpoints). We would like to apply the skin to all views from one skin assembly, which we can change using another skin assembly to apply a different skin (not necessarily at runtime, this could be done at compile time) and change only a few lines of code. And here is the kicker ... we want it to display correctly in the designer of Visual Studio 2008.

Currently, we have a solution for executing skins that applies the appropriate skin by merging the main resource dictionary of the skin with Application.Resources, but the designer of the visual studio does not show this skin in the views in the dependency assemblies.

We could combine the resource resource dictionary into each separate Window.Resources view, but this is a performance hit and requires a lot of changes if we want to change the skin.

I looked at applying theme-level styles, but to use a theme-level style, you need to specify a ComponentResourceKey with a strongly typed reference to the theme assembly type. This requires that each view indicates the namespace in which the skin is located, and again will be the main refactor for replacing skins.

Other ideas?

+3
source share
1 answer

You can use the attached behavior to combine your resource dictionary into each window / page / usercontrol resource, for example:

<Page my:Skinlibrary.Attach="True">
   <!-- stuff goes here -->
</Page>

You can customize the attached behavior to always combine the same instance of the resource dictionary with the attached resources of the element. To do this, you need to initialize the resource dictionary only once, possibly in a static ctor.

Assuming you have ready-made resources in the variable "_staticResourceDictionaryThatHoldsMySkin", then in the "PropertyChanged" callback of the attached property, you can do this to combine it into the attached windows:

static void OnAttachChanged(DependencyProperty sender, DependencyPropertyChangedEventArgs e)
{
   (sender as FrameworkElement).Resources.MergedDictionaries.Add(_staticResourceDictionaryThatHoldsMySkinResources);
}

, SkinLibrary. , .

, Visual Studio, 2008 , 2010 .

+3

Source: https://habr.com/ru/post/1762762/


All Articles