Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
115
XamDockManager tab content creation policy
posted

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,

Parents
  • 54937
    Verified Answer
    Offline posted

    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.

Reply Children