How can i apply a style to, for example, a button, when using the new ThemeManager to theme MS WPF controls? If I apply any style, the IG theme is disregarded? See the sample app. It shows a button with an explicit style that just sets its width and height. But when i apply it to my button, the button no longer takes the properties from the ThemeManager. I tried BasedOn, it didn't help. Also, Implicit styling of a button seems to be ignored (commented out in my sample as to show No Style). Is there a way to accomplish styling the button based of the IG Theme?
Hi Travis,
Your BasedOn style actually does work but because of the order in which things are added to the Application.Resources, the ThemeManager resource dictionary is getting priority over the based on Button style. The first dictionary added to the Application.Resources.MergedDictionaries collection is your explicit styles one. After which the IG Theme resource dictionary is added. Since it was added second, it's resources have priority.
If you move your resource dictionary into the MainWindow.Resources you'll see that your BasedOn style works. So in order for your custom styles to be used, they need to basically be added after the ThemeManager's resources.
Given that i use this button theme throughout my application (many windows etc), is there a way i can delay or otherwise get the style to be applied in a way that will allow it to work other than placing it in EVERY window's resources? Thanks
After moving the resource dictionary into MainWindow, the IG theme still doesn't appear to be applied. Notice the first two buttons still don't have the IG theme applied (they are not square, etc. like the 3rd button). Maybe i misunderstood your comments, but moving the ResourceDictionary doesn't seem to have any affect for me. Included modified sample. If this works for you, please modify the sample to show me exactly how you did it.
Thanks a lot for your interest in ThemeManager.
Actually what Rob suggested works except in the latest Service Release - WPF.Nightly_14.2.20142.2081 :) That is so because of the fix for the issue you reported with your previous thread where it was throwing an exception when having plain XamDataGrid. In order to fix it we had to do the loading of the xaml resources asynchronously. So what is happening in your sample when your custom styles get parsed the ThemeManager hasn't loaded the RD(ResourceDictionary) containing the implicit styles yet.
I wouldn't recommend applying a theme to a specific part of the VisualTree(like MainWidnow) because of a limitation of WPF documented here. Basically some dialogs(popups) used by some controls does not get affected of the styles when they are not applied on Application level.
I've attached a sample solution that should be working well for you. In a nutshell we're creating new RD and instructing the TM to to load that new RD instead of the one it is loading by default. In order not to loose the styles containing the implicit styles we need to merge it to the RD we created. Here's a doc article explaining the process of creation of a custom theme.
I hope this would work well for you. If you need any other assistance with this please don't hesitate to ask.
Thanks for your response. Unfortunately, the sample you provided does not run.
'Provide value on 'System.Windows.StaticResourceExtension' threw an exception.' Line number '16' and line position '38'.
The Styles for Style1 and Style2 buttons are not found...
My bad. Really sorry!
I was testing against a build with the async fix disabled and fooled myself.
The solution I provided doesn't work for the same reason Rob's suggestion does not.
At this point the only solution I found is referencing the resources by using DynamicResource instead of StaticResource.
Another thing is that you need to base your style on the keyed resource for the button style of the theme - you could find the RC that is applying the implicit styles looking at the bottom of C:\Program Files (x86)\Infragistics\2014.2\WPF\Themes\Metro\Metro.MSControls.Core.Implicit.xaml. This dictionary is what the TM is loading if StyleMicrosoftControls is true (the default value).
I've attached modified sample using DynamicResource and the custom styles are based on {StaticResource ButtonStyle}.
Sorry once again for the confusion and hope this one do work for you.
Forgot to mention that forcing you to use DynamicResource is not ok and I'll spend some more time trying to find a better solution.
Hello Travis,
Thank you for your reply and the feedback on this issue. I have been further investigating and currently, the approach I have suggested in my previous reply seems to be the best in the scenario that you are having.
We are continuously working on improving the quality of the controls and your feedback is valuable in this process. If you have any suggestions on what we can change in Themes/TheamManager to make it more easy to use and better for you, it would be great to share your thoughts on that matter. You can do that here in the forums or you can also create a support ticket through our website or submit a new Product Idea for something that you think it will help improving our products.
If I can assist you with anything else, please do not hesitate to ask.
i've simply given up on infragistics themes, there always another problem. not worth the time...
I've been wandering did you manage to check out my last suggestion and is it working for you.
I'll be glad to help further if needed.
Thanks,
Sorry for the late response.
The alternative on using DynamicResource is to manually add RCs from the theme containing the styles you need to extend to your application resources. This way you don't need to subclass the theme class. Using this approach you could also base your extended styles on the implicit ones from the theme - i.e. BasedOn="{StaticResource {x:Type Button}}".
Check out the attached sample solution.
Hope this helps,
any solution yet?