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:
*bump*
This is killing my app, 10 days no response?
Hello,
I think the problem is coming from the incorrect usage of the DataTemplate.
If you want each ContentPane to use this DataTemplate for its Content, then you should create a style for the ContentPane and set this DataTemplate to the ContentTemplate property.
If you want a ContentPane to have a PlateView element for its content, then you should put a PlateView element as direct content.
When you are setting the Content of a Control directly, you should put the element directly. If you want to provide a customization for that content, then you use a Template. I doubt that I can explain this better than the MSDN, so you can take a look this great article here.
Thanks for the response Alex.
I will try to set the ContentPane style as you suggest, because each content pane in my app needs to display one usercontrol, like the plate view.
I dont want to set the plate view element directly in the content pane because then I lose access to the ViewModel properties in the xaml- and I would prefer to keep them in the viewmodel than the view along mvvm lines.
I am a little confused as to the difference between setting the ContentPane style for the data template and just using a data template like I was doing, it would be much appreciated if you could explain a bit!
Thanks!