Hello,
I'm seeing an issue whereby when we set the theme in our application as follows:
ThemeManager
.CurrentTheme = theme;
where 'theme' is one of your preset themes - some of our controls seem to become unloaded. For example, combo boxes (both yours and standard WPF) would not show the popup (or popdown). When debugging I could see that the controls which were not responding have the property 'IsLoaded' set to false.
If the theme is set for the application, are you unloading controls in the background?
Thanks in advance.
We aren't directly loading or unloading elements. I have an article which in the background section discusses how theming works but basically when you set the Theme property, we put resources (Styles/Brushes/etc) into the ResourceDictionary where you have set the Theme. Since those styles have a Template setter, that will cause any element which picks up that local style to have its template changed. So in that case that element's descendants would be unloaded. I have seen some issues in the WPF framework where the IsLoaded property gets into a bad state because of some seemingly fragile code in IsLoaded which as part of its resolution considers whether objects are hooked into the loaded or unloaded events of it or its descendants as criteria for whether it is loaded or not. Do you have a simple project that demonstrates the problem you are seeing?
Unfortunately I don't have a project which is small enough to upload. I have tried to recreate it, but in a small app it seems to work fine.
Do you have any pointers which we could try out to see if we could resolve the issue? It does sound like that it's a problem with WPF rather than the ThemeManager, but changing the theme using the ThemeManager was the only way we got this behaviour.
Reproducing this in a simple may be difficult. When I have seen this it has been related to having descendant elements that have hooked the Loaded event (which is a valid thing but as I mentioned the IsLoaded state seems to make some assumptions based on the event being hooked). So it might be easier to take the existing project, make a copy of it, remove the code behind that you can (in all likelihood the code isn't needed unless you have code that is creating/manipulating the ui), and then start to remove unnecessary elements. Even if you can't remove the elements, if you can get it to the point where that can be run and the problem is demonstrated we can take a look. Since this will be related to your real project you'll probably want to submit the project directtly to the support group rather than posting it here.
If you want to try and debug this in your actual app the first thing you may want to do is to use Snoop and walk up the visual tree until you find the first element whose IsLoaded is false. What element is that? What is the ancestor element that removed it from its visual tree (e.g. it may be in a contentpresenter but what is that contentpresenter's templatedparent)?
BTW there were some cases where this came up inside the xamRibbon and xamDockManager and we were able to get around it - at least in the specific scenarios we found. So if you're using those controls and they are ancestors of the elements having an issue its possible that the issue may not happen in the latest versions. I don't know what version you are using or what controls the problem controls are within so I can't be sure.
Thanks for your response again.. Unfortunately, I don't think it will be possible to split the app up and strip out the bits we need without doing some major fiddling and hopefully it won't come to that!
However, I've had a look at Snoop and gone through the visual tree. The going up the visual tree, the first thing that isn't loaded is a 'SplitPane' in the following:
XamDockManager -> AdornerDecorator -> Border -> DockPanel -> PART_Panel (DockManagerPanel) -> **SplitPane**
It seems as though it's the descendants of the PART_Panel which aren't loaded (or rather where IsLoaded is false) and it sounds like the issue you described with the xamDockManager. We're using version 10.2, which version were the problems you mentioned fixed in?
That issue was fixed back in July (and was fixed in 9.1 and forward) so try getting the latest hotfix for 10.2 and retesting.
We got the latest hotfix (version 10.2.20102.2139 - is that the right one?) and re-tested. We're still getting the same issue. I will try and cobble together an example which I can upload here.