Hi,
I have a XamDockManager working as MDI. My problem is:
I load a view in a tab “A”, this view contains a control (I’ll call it “X” ), this control “X” has a collection. From another process I fire an event that is being listened by this control “X”. What I noticed is, if I open another tab and then return to the tab “A”, the view contained in this tab is recreated and so is the control “X” (constructor is called again), therefore the collection is null. My question is: Is this the right behavior? If it is how can I avoid it from a tab or control perspective? Or Is there a work around I could do?
Henry Smith,
Hello Henry,
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.
Thanks for the quick response, I understand what's going on.... A change in this level might compromise the project.. We decided to go around the issue and came up with another solution from a different perspective.
Thanks,
As Stefan pointed out this is probably happening because of how the TabControl works (the TabGroupPane is a derived TabControl). The TabControl has a single ContentPresenter that is used to bind to the Content(Template(Selector)) of the selected TabItem. So as a tab is selected, the old tab's info is no longer referenced by the tabcontrol's ContentPresenter and therefore its content comes out of the visual tree (if its an element) and the contenttemplate is released. That being said the ContentPane is the content of the PaneTabItem so the Content of the TabGroupPane will be the ContentPane itself. I'm assuming the control you mention is used within a DataTemplate but where is that datatemplate being used? If this is used for the ContentTemplate of the ContentPane then it's possible that if you're using theming or some other means of providing a style/template for the contentpane that this could happen as a result of the contentpane coming out of the visual tree because WPF would temporarily change the template/style because it wouldn't have access to the implicit one. If that's the case then you might be able to work around this by putting a ContentControl as the Content of the ContentPane and instead of setting the Content(Template(Selector)) properties on the ContentPane, you could set it on that ContentControl.
Thank you for your post. I have been looking into it and I can say that due to performance optimizations and the XamDockManger virtualization, when you change the Tab the content is unloaded and when you select it again it is recreated, so the behavior you have is expected. If you want I can log a Product Idea for you for an ability to control the virtualization.
Looking forward for your reply.