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
415
Dockmanager creating two instances?
posted

I have a usercontrol in a content pane.  If I use mvvm datatemplate to create my view:

    <DataTemplate DataType="{x:Type platevm:PlateViewModel}" >

        <plate:PlateView />

    </DataTemplate>

The view is instantiated twice if in a content pane.  So:

<Grid>
    <igDock:XamDockManager>
        <igDock:XamDockManager.Panes>
            <igDock:SplitPane>
                <igDock:ContentPane>
                    <platevm:PlateViewModel />
                </igDock:ContentPane>
            </igDock:SplitPane>
        </igDock:XamDockManager.Panes>
    </igDock:XamDockManager>
</Grid>
Creates two instances of the PlateView.  If I switch to <plate:PlateView /> only one is created.  
Why is this?  It is really messing with some of my code....

Parents
  • 54937
    Verified Answer
    Offline posted

    In trying this with a new project I do not see the problem you are describing. I can guess as to what is happening. Basically the ContentPane is a ContentControl. When you set the Content property of a ContentControl, it is not the ContentControl itself that searches for and uses the datatemplate - it is the ContentPresenter within its Template. So if the Template of the ContentControl (ContentPane or otherwise) is changed, then the ContentPresenter in the new template must create its own instance of the DataTemplate's content. So I'm guessing that you are doing something that is causing the ContentPane's Template to be changed - e.g. setting the Theme property, changing the OS theme, etc. One thing that may work for you is to just set the Content to be a ContentControl and set the Content of that to be your object. In this way, the template of the containing ContentControl would not be changed and so only 1 instance should be created. e.g.

        <Window.Resources>
            <DataTemplate DataType="{x:Type local:Foo}">
                <local:UserControl1 />
            </DataTemplate>
        </Window.Resources>
        <igDock:XamDockManager x:Name="dm">
            <igDock:XamDockManager.Panes>
                <igDock:SplitPane>
                    <igDock:ContentPane>
                        <ContentControl>
                            <local:Foo />
                        </ContentControl>
                    </igDock:ContentPane>
                </igDock:SplitPane>
            </igDock:XamDockManager.Panes>
        </igDock:XamDockManager>

    Of course if you have any code that assumes that the logical parent of your viewmodel is the ContentPane then you would have to change that accordingly.

Reply Children