Silverlight AutoCompleteBox DataTemplate

This is more a note for myself how to do this. The Silverlight 4 SDK contains a pretty good AutoCompleteBox that you can use. Download/install the SDK and and the control will be available in your Silverlight Controls Toolbox.

If you try to use this with RIA Services, you may notice it is displaying the Id/Key in the dropdown, but you yourself want to show a name or description. In that case you have to add a DataTemplate section to the AutoCompleteBox:

<sdk:AutoCompleteBox x:Name="FilterTextBox"
                       FilterMode="Contains"
                       MaxDropDownHeight="150"
ItemsSource="{Binding Data, ElementName=dds}"
                       ValueMemberBinding="{Binding Name}">
    <sdk:AutoCompleteBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Name}" />
        </DataTemplate>
    </sdk:AutoCompleteBox.ItemTemplate>
</sdk:AutoCompleteBox>

That should do it.

1 Comment

Comments have been disabled for this content.