Question

How to get Themes working inside an ElementHost (FormsIntegration)

Posted 3 years ago by Avatar keepITcool - Amsterdam

I am building an Office Addin using WPF for my usercontrols.  I interact with user via CustomTaskPane so I have to use a Forms.Usercontrol with a FormsIntegration.ElementHost which hosts the WPF

My problem:   CurrentTheme changes are not reflected on my UI.. and I've been trying and typing and cursing a lot over the past days.

When I ran the same control directly in a WPF Window everything works as expected... which is when I realized that apparently the ElementHost is interfering somehow.  I can partly solve it using an eventhandler for CurrentTheme which uses SetTheme on individual controls, but that's error prone and cumbersome.

Anyone know how to solve this the correct way?

Regards,

Jurgen

Example code can be supplied in a simplified VB.project


Comments (2)

Posted 3 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Jurgen,

Our themes just set the App.Resources collection when you set the ThemeManager.CurrentTheme property.  Perhaps when used in an ElementHost, the Application object never instantiates an Application.Current value though since it's not a WPF app.  And if that is the case, I'm not sure if you can manually create one either.

You might be able to use the ThemeManager.SetTheme method directly on your root WPF control in the ElementHost, and have it work that way.  If you have more than one ElementHost though, I'd imagine that you'd need to do that in each root WPF control in an ElementHost.  It's a pain but there's probably no other way if there is no current Application for them to inherit resources from.


Actipro Software Support
Posted 3 years ago by keepITcool - Amsterdam

Thanks for that reply. I've been working with WPF since a few months only..

I have it working now.. BUT with some caveats..

1) Updating the ThemeManager must be done at the very start of my code, before creating any UI elements.
     AFAIK  Office doesnot expose Theme property nor ThemeChange event but I read it from the registry and statically set the my UI theme.

2) Standard office themes appear to have no effect BUT custom themes based on standard officethemes work correctly. 
No problem as I want to control Tint anyway.

    ThemesOfficeThemeCatalogRegistrar.Register()
    ThemeManager.RegisterThemeCatalog(New TintedThemeCatalog("MyOfficeBlue", ThemeName.OfficeBlue.ToString, Colors.SteelBlue))
    ThemeManager.RegisterThemeCatalog(New TintedThemeCatalog("MyOfficeBlack", ThemeName.OfficeBlack.ToString(), Colors.Black))

3)  Setting AreNativeThemesEnabled in my initializer appears to have no effect BUT works fine when my usercontrol.xaml sets it with markup.

4)  Scrollbar default style override created in my own resourceDictionary. I still need to do some work on the Itemspresenter for combobox :-)

5)  I use SetTheme on the ElementHost.Child via an eventhandler...  and it inherits fine in the content.
     your answer made me realize I have to research FormsIntegration to see how ElementHost implements the Application object

Thanks

 

 


   

 



 


2) The standard office themes  


Add a Comment

Please log in to a validated account to post comments.