I have a ToolBar with 3 DataTemplates for my elements:
<ToolBar ItemsSource="{Binding ContextActions}" Background="Transparent" ToolBarTray.IsLocked="True"> <ToolBar.Resources> <DataTemplate DataType="{x:Type viewModels:SimpleContextActionViewModel}"> <Button Command="{Binding ActionCommand}" Style="{StaticResource ToolBarButtonStyle}" ToolTip="{userInterface:Translation Binding={Binding ToolTip}}"> <ContentControl Template="{Binding Icon,Converter={StaticResource NameToResourceConverter}}" Margin="5" /> </Button> </DataTemplate> <DataTemplate DataType="{x:Type viewModels:SeparatorViewModel}"> <Rectangle Fill="{StaticResource SeparatorBrush}" Width="1" VerticalAlignment="Stretch" Margin="2,7" /> </DataTemplate> <DataTemplate DataType="{x:Type viewModels:PopupContextActionViewModel}"> <Grid> <ToggleButton IsChecked="{Binding ElementName=ContextActionPopup, Mode=TwoWay,Path=IsOpen}" Style="{StaticResource ToolBarButtonStyle}" ToolTip="{userInterface:Translation Binding={Binding ToolTip}}"> <ContentControl Template="{Binding Icon, Converter={StaticResource NameToResourceConverter}}" Margin="5" /> </ToggleButton> <Popup Name="ContextActionPopup" Height="150" Width="150" StaysOpen="False"> <Border BorderBrush="{StaticResource PopupBorderBrush}" BorderThickness="1" Background="White"> <ContentControl userInterface:RegionHelper.RegionName="{Binding RegionId}" /> </Border> </Popup> </Grid> </DataTemplate> </ToolBar.Resources> </ToolBar>
The ItemsSource element is an ObservableCollection <object>
The first three elements are already available in the constructor of my ViewModel, the three use DataTemplates as expected.
If I add another "SimpleContextActionViewModel" to the ObservableCollection, the ToolBar will add a ContentPresenter that calls ToString. If I add the following line to translate the ObservableCollection to a new one, everything will be fine:
this.ContextActions = new ObservableCollection<object>(this.ContextActions);
this initiates the NotifyPropertyChanged implementation of my ViewModel, and all the elements are recreated and look normal.
Why doesn't the CollectionChanged of my ObservableCollection select a valid DataTemplate, but does the PropertyChanged ?.
This is how it looks 
source share