Silverlight Telerik RadComboBox Hell

There’s really nothing very *rad* about the thing, is there? ComboBox-Binding can be VERY frustrating. Here’s hoping some poor soul out there finds this in his or her time of need.

Here’s one utilizing a virtual stackPanel to improve performance with large datasets. It also sets the width to avoid the ugly resizing that occurs when the control recalculates its size on the fly. For items that fall off the drop down’s map: a handy tool-tip.

This guy was tricky because you can’t simultaneously use an ItemTemplate (necessary for the tooltip) and the SelectedValuePath property (necessary to display your value).

ENJOY!

-Ryan

<DataTemplate x:Name="ownersComboBoxItemTemplate">
    <TextBlock Text="{Binding Path=CompanyName}">
        <ToolTipService.ToolTip>
            <ToolTip Content="{Binding Path=CompanyName}" />
        </ToolTipService.ToolTip>
    </TextBlock>
</DataTemplate>

<telerik:RadComboBox x:Name="OwnerComboBox" ItemsSource="{Binding Owners}"
                        SelectedValue="{Binding SelectedOwner, Mode=TwoWay, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}"
                        telerik:TextSearch.TextPath="CompanyName"
                        EmptyText="Select an owner..."
                        Style="{StaticResource RadComboBoxStyle}"
                        ItemTemplate="{StaticResource ownersComboBoxItemTemplate}"
                        ClearSelectionButtonContent="-- No Selection --"
                        ClearSelectionButtonVisibility="Visible">
    <telerik:RadComboBox.ItemsPanel>
        <ItemsPanelTemplate>
            <VirtualizingStackPanel Width="300" MaxWidth="300" ScrollViewer.HorizontalScrollBarVisibility="Auto" />
        </ItemsPanelTemplate>
    </telerik:RadComboBox.ItemsPanel>
</telerik:RadComboBox>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s