I need to create a custom ComboBox with 2 ItemsPresenter but I don't know how to set the ItemsPresenter where to add and remove items.
I have tried to get the ItemsPresenter:
ItemsPresenter itemsPresenter = (ItemsPresenter)comboBoxAlbum.FindName("ItemsPresenterAlbum");
but I don't know how to get the Items collection.
This is how I have modified the Popup part:
<Popup x:Name="PART_Popup" AllowsTransparency="True" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Margin="1" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
<Themes:SystemDropShadowChrome x:Name="shadow" Color="Transparent" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=templateRoot}">
<Border x:Name="DropDownBorder" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
<Grid Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="100*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Background="#FF929CA4">
<ScrollViewer Background="#FF929CA4">
<Grid x:Name="ToolBar" SnapsToDevicePixels="True" Background="#FF929CA4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<StackPanel x:Name="btnStretchNone" MouseUp="btnStretch_MouseUp" Grid.Column="0" Background="{Binding BtnStretchNone}" Style="{DynamicResource StakPanelEffect}">
<Image Width="32" Height="32" Margin="5" Source="Resources/StretchNone.png"/>
</StackPanel>
<StackPanel x:Name="btnStretchFill" MouseUp="btnStretch_MouseUp" Grid.Column="1" Background="{Binding BtnStretchFill}" Style="{DynamicResource StakPanelEffect}">
<Image Width="32" Height="32" Margin="5" Source="Resources/StretchFill.png"/>
</StackPanel>
<StackPanel x:Name="btnStretchUniform" MouseUp="btnStretch_MouseUp" Grid.Column="2" Background="{Binding BtnStretchUniform}" Style="{DynamicResource StakPanelEffect}">
<Image Width="32" Height="32" Margin="5" Source="Resources/StretchUniform.png"/>
</StackPanel>
<StackPanel x:Name="btnStretchUniformFill" MouseUp="btnStretch_MouseUp" Grid.Column="3" Background="{Binding BtnStretchUniformFill}" Style="{DynamicResource StakPanelEffect}">
<Image Width="32" Height="32" Margin="5" Source="Resources/StretchUniformFill.png"/>
</StackPanel>
<StackPanel x:Name="btnSettings" MouseUp="btnSettings_MouseUp" Grid.Column="4" Background="{Binding BtnStretchFrame}" Style="{DynamicResource StakPanelEffect}" IsEnabled="False">
<Image Width="32" Height="32" Margin="5" Source="Resources/SettingsB.png"/>
</StackPanel>
</Grid>
</ScrollViewer>
</Grid>
<Grid Grid.Row="1">
<TabControl Height="{Binding ActualHeight, ConverterParameter=-42, Converter={StaticResource AdditionConverter}, ElementName=DropDownBorder}">
<TabItem Header="Albums">
<ScrollViewer x:Name="DropDownScrollViewerAlbum">
<Grid x:Name="gridAlbum" RenderOptions.ClearTypeHint="Enabled">
<Canvas x:Name="canvasAlbum" HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
<Rectangle x:Name="OpaqueRectAlbum" Fill="{Binding Background, ElementName=DropDownBorder}" Height="{Binding ActualHeight, ConverterParameter=-72, Converter={StaticResource AdditionConverter}, ElementName=DropDownBorder}" Width="{Binding ActualWidth, ConverterParameter=-8, Converter={StaticResource AdditionConverter}, ElementName=DropDownBorder}"/>
</Canvas>
<ItemsPresenter x:Name="ItemsPresenterAlbum" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Grid>
</ScrollViewer>
</TabItem>
<TabItem Header="Slides">
<ScrollViewer x:Name="DropDownScrollViewerSlide">
<Grid x:Name="gridSlide" RenderOptions.ClearTypeHint="Enabled">
<Canvas x:Name="canvasSlide" HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
<Rectangle x:Name="OpaqueRectSlide" Fill="{Binding Background, ElementName=DropDownBorder}" Height="{Binding ActualHeight, ConverterParameter=-72, Converter={StaticResource AdditionConverter}, ElementName=DropDownBorder}" Width="{Binding ActualWidth, ConverterParameter=-8, Converter={StaticResource AdditionConverter}, ElementName=DropDownBorder}"/>
</Canvas>
<ItemsPresenter x:Name="ItemsPresenterSlide" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Grid>
</ScrollViewer>
</TabItem>
</TabControl>
</Grid>
</Grid>
</Border>
</Themes:SystemDropShadowChrome>
</Popup>
There are 2 ItemsPresenter (ItemsPresenterAlbum, ItemsPresenterSlide). How can I add items to a specific ItemsPresenter? Using the Items.Add() it add only to the second ItemsPresenter.