I have an mvvm framework much like Josh Smith's sample. Problem is that I've just discovered that every time I display a viewmodel, for some reason, the associated view constructor is firing TWICE. And this is messing things up elsewhere in the app. Of course, in both case, the call stack is empty, external, so I can't tell who is doing the 'newing'. I know it's not me, I don't 'new' the view anywhere. It's not duplicate datatemplates because it doesn't even allow duplicate templates.
1) How can I figure out who is newing the view?
2) how can I get hooked into the "magic" between newing my viewmodel, and when the behind the scenes of WPF auto figures out what view to use and news the view?
MORE INFORMATION:
Just like Josh Smith example, I have datatemplates that associate a viewmodel to a view. Just like Josh Smith, I have a collection of viewmodels bound to a tab control. When a new viewmodel is created and added to that collection, the magic box uses the datatemplates in the xaml to figure out the view, the magic box news the view, binds the datacontext of the view to my viewmodel and a new tab appears. All this happends behind the scenes within .net. I never new the view. I only new the viewmodel and then add it to a collection.
NARROWED DOWN TO PROBLEM XAML:
If I use the ComboBox, for some reason, that causes a new view to be created from the Items collection which is a list of ViewModels. But if I use the menu, the extra view is not created.
<!--
<ComboBox Name="TabMenus" ItemsSource="{Binding RelativeSource= {RelativeSource FindAncestor, AncestorType={x:Type lc:MultiStepPanel}}, Path=Items}" Width="15" Height="15" Margin="2" >
<ComboBox.ItemContainerStyle>
<Style TargetType="ComboBoxItem" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<TextBlock Text="{Binding VisibleDisplayName}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
-->
<Menu Name="TabMenus" Style="{StaticResource TabMenuDropDownStyle}" >
<MenuItem Style="{StaticResource TabMenuButtonStyle}"
ItemsSource="{Binding RelativeSource= {RelativeSource FindAncestor, AncestorType={x:Type lc:MultiStepPanel}}, Path=Items}"
ItemContainerStyle="{StaticResource TabMenuItem}" />
</Menu>
Both controls have the exact same ItemsSource xaml. Why does the combo trigger a new view?