I am developing Windows phone 8.1 RT app. I am using Combobox. There are more than 20 Operators to be bind to the Combbox. when we tab on the Combobox, App should open the all 20 opetaros in full mode. I need
two different templates, should use one template (image and textblock) when items opens in Full mode and other template (only TextBlock) when a item selected among full mode items. DataTemplateSelector is inherited
and created new DataTemplateSelector. ItemTemplateSelector is assigned with newly inherited DataTemplateSelector. Below the is code used.
<ComboBox Grid.Row="3" Grid.Column="0" Margin="15 5 0 0"
ItemsSource="{Binding Operators}" SelectedItem="{Binding SelectedOperator, Mode=TwoWay}"
Style="{StaticResource FullModeComboBoxStyle1}" ItemContainerStyle="{StaticResource FullModeComboBoxItemStyle1}"
VerticalAlignment="Top"
Height="65"
ItemTemplateSelector="{StaticResource ExploreTemplateSelector}"
/>
public class ExploreTemplateSelector : DataTemplateSelector
{
public DataTemplate DropdownItemsTemplate { get; set; }
public DataTemplate SelectedItemTemplate { get; set; }
protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
{
var parent = container;
while (parent != null && !(parent is ComboBoxItem) && !(parent is ComboBox))
parent = VisualTreeHelper.GetParent(parent);
var inDropDown = (parent is ComboBoxItem);
return inDropDown
? DropdownItemsTemplate
: SelectedItemTemplate;
}
}
<DataTemplate x:Key="OperatorDataTemplate">
<StackPanel Orientation="Horizontal" Margin="5 5 0 0" Height="Auto">
<Image Source="{Binding ImageUri}" Height="35" Width="60" VerticalAlignment="Top" />
<TextBlock Text="{Binding Name}" Style="{StaticResource ComboboxTextBlockStyle}" Margin="5 0 0 0" Width="120" VerticalAlignment="Top" TextWrapping="Wrap"/>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="SelectedOperatorDataTemplate">
<TextBlock Text="{Binding Name}" Style="{StaticResource ComboboxTextBlockStyle}" Margin="5 0 0 0" Width="120" VerticalAlignment="Top" TextWrapping="Wrap"/>
</DataTemplate>
<class:ExploreTemplateSelector x:Key="ExploreTemplateSelector" DropdownItemsTemplate="{StaticResource SelectedOperatorDataTemplate}"
SelectedItemTemplate="{StaticResource SelectedOperatorDataTemplate}"
/>
Items are not binding when we tab the Combobox, showing list of namespace. But selecting a item in full mode, SelectTemplateCore is hitted and Selected item is showed using SelectedItemTemplate. But SelectTemplateCore is
not hitted when binding Operators.
What is the problem in this code? Why DropDownItemsTemplate is not used to bind the items?
Thanks in advance