سؤال

I have a 'theme engine' I have created that houses resource dictionaries and a custom combobox to change the skin of an application. This is wrapped in a .dll file and the intention is to be able to reference this .dll from any new application and have the skin logic ready to go. I have worked out most of the problems with this project with relative ease but I'm left with one massive problem... In the application that calls the .dll it is possible to set a property such as background of an element using the Background = "{DynamicResource XKeyOfBrushIWantToUse}" but there's a compile-time warning that states "The resource "XKeyOfBrushIWantToUse" could not be resolved. This makes sense because the .dll hasn't been loaded yet. Once I run the application, it is able to now find this resource and use it appropriately. What I want is for a way to know what the brush x:key properties are at compile-time / design-time so that when I set a property to a value, I can know what options are available.

For example in my .dll there's a brush who's x:key="MainWindowBackgroundBrush". This brush's color property changes based on which resourcedictionary containing colors is loaded. (i.e. BlueColors.xaml has a color who's key is BackgroundColor, so does RedColors.xaml. at runtime I can swap the colors files and the brushes will still point to "BackgroundColor" though the hex value of the color is now different) Now when I go to a new application and reference the .dll and set the Background color of say a button, I have to KNOW what the keys of the brushes are because I haven't found a way to expose the available keys from the .dll.

Help is greatly appreciated!!!!

هل كانت مفيدة؟

المحلول

DevExpress has come up with an interesting way to resolve this, they basically have a set of Enums for every particular element and style, and a MarkupExtension that recieves a value from this enums and returns the appropiate string key. That way you can do things like:

<Style BasedOn="{StaticResource {dxgt:GridRowThemeKey ResourceKey=CellStyle}}"> 
  <!-- and so on... -->
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top