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:
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.
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.
I have same problem bit more complicated. I want to bind collection of viewmodel to tabgroup panel.
<Window.Resources>
<DataTemplate DataType="{x:Type local:Foo}">
Excellent help guys! Gold stars for both of you.
Simply putting my viewmodel in <ContentControl> tags solved the problem and only took about 5 minutes to update everything.
Cheers!