When the themes were loaded via a resource dictionary all of the brushes and colors were accessible via static resources.
Ie Brush01 through Brush05 and could be used to style elements in the application so when you changed the theme, these styles would also update.
I can't seem to find any means for accessing these resources at runtime. Is this possible with the theme manager?
Jesse
Hi Jesse,
as I mentioned in my previous response our theme xaml files are structured in a such a way so all the commonly used parts(i.e. colors, brushes, styles and templates) are defined in Styles.Shared.xaml & Theme.Colors.xaml & Styles.WPF.xaml. Since these are referenced in almost (if not all) specific xaml file styling a particular control. This includes the implicit styles for MS intrinsic control(ie Button). So if you haven't disabled the styling of the MS core controls you should be fine referencing this parts(ie Color_28) as static resources provided you've applied the theme prior to parsing the xaml which is referencing the Color_28.
I hope the above is clear enough. If not please feel free ask for further assistance.
Another effect of this is that static resources that were available before are no longer available if not used in one of the built in control styles. Ie if Color_28 is not in use on any of the styles applied to controls I have in use then referencing it will throw an exception.
I would like to see the theme manager put all colors and brushes into the resource dictionary regardless of if they're used.
Jesse Hamilton said:Is there any means of accessing these resources at design time?
Unfortunately, at this point the ThemeManager does not support design time. I'll spend some time to see if this could be workarounded somehow.
Jesse Hamilton said:Does the documentation have a reference for these resources and what their values are for each of the different themes?
The ThemeManager job is basically monitoring what controls are used by the application and includes the corresponding resource dictionaries as you would have done if you have to include these xaml resource dictionaries the old way. So you need to check out the .xamls. For example each theme has most of its reusable parts defined in Styles.Shared.xaml & Theme.Colors.xaml files - including brushes and colors. I suppose there you could find out what is what.
You could probably partially fix the designer complaining for these StaticResources by manually(the old way) apply these shared dictionaries I mentioned above. This will fix the errors you're getting during design time. It really doesn't matter which one from which theme exactly you get the shared resource dictionaries since these brushes and colors are common through out all the themes. It probably make sense adding the ones with the theme you plan to use. This could be used as a dev time fix so the designer could operate.
Hope this helps,
Ahhh, gotcha, so these resources will be resolved because the theme manager loads the same resource dictionary when applying an application theme.
Is there any means of accessing these resources at design time? Does the documentation have a reference for these resources and what their values are for each of the different themes? It would be nice to have design time support, after moving to the thememanager from the resource dictionaries visual studio can't resolve the staticresources at design time and throws errors into the error list.
Hi Jessie,
you need to set the theme anytime before the xaml where you're binding to these brushes gets parsed. For example if you set the ApplicationTheme on OnStartup override of the App class the theme manager will pull this core resources and will merge them with the resources of the app. Check out the attached sample.
BTW if you set the StyleMicrosoftControls property to false( of the theme object that you're feeding to the ThemeManger.ApplicationTheme) like follows:
ThemeManager.ApplicationTheme = new MetroDarkTheme(){StyleMicrosoftControls = false };
you'll get an XamlParseException since when we're not styling the intrinsic MS controls we're not loading any resource dictionaries until there is need(that is when a control is regitered with the ThemeManger - check out this help topic).