I've found the code to override the template selection:DataTemplateSelector
But the collapsed state of the combobox is not working.
Here is the XAML:<
telerik:RadComboBox
x:Name
=
"cboPickups"
Command
=
"{Binding PickupChangedCommand}"
HorizontalAlignment
=
"Stretch"
CommandParameter
=
"{Binding ElementName=cboPickups,Path=SelectedItem}"
IsEnabled
=
"{Binding CanSelectPickup}"
ItemsSource
=
"{Binding Pickups}"
SelectedValuePath
=
"CustomerId"
SelectedValue
=
"{Binding Path=SelectedPickup.Id, Mode=OneWay}"
Margin
=
"4"
>
<
telerik:RadComboBox.ItemTemplateSelector
>
<
Helpers:CustomerComboTemplateSelector
/>
</
telerik:RadComboBox.ItemTemplateSelector
>
</
telerik:RadComboBox
>
Here are the templates:
<
DataTemplate
x:Key
=
"CustomerComboCollapsed"
>
<
TextBlock
Text
=
"{Binding CompanyName}"
/>
</
DataTemplate
>
<
DataTemplate
x:Key
=
"CustomerComboExpanded"
>
<
StackPanel
>
<
TextBlock
Text
=
"{Binding CompanyName}"
/>
<
TextBlock
Text
=
"{Binding CityState}"
/>
</
StackPanel
>
</
DataTemplate
>
Here is the template selector class:
public override System.Windows.DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container)
{
var presenter = (ContentPresenter) container;
if (presenter != null && item != null)
{
if (presenter.TemplatedParent is ComboBox)
{
return presenter.FindResource("CustomerComboCollapsed") as DataTemplate;
}
else
{
return presenter.FindResource("CustomerComboExpanded") as DataTemplate;
}
}
return null;
}
But when the window initializes and it tries to load the ComboBox
, the "container" is null.
So it's trying to assign the collapsed template, but for some reason the container is null. Any ideas? I've narrowed it down to the RadComboBox. If I replace it with the base ComboBox control it works fine.
I've attached the screen shots for the collapsed/expanded and the debugger.
Thanks,
-Sid.