This is a migrated thread and some comments may be shown as answers.

[Solved] ItemTemplate

3 Answers 94 Views
AutoCompleteBox for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Simon
Top achievements
Rank 1
Simon asked on 19 Sep 2013, 10:56 AM
Hello.

I need help how to set to autocompletebox own itemTeplate like in ComboBox in normal Windows 8 controls.

I have Customer class object with property Name and CustomerNo and need both to show in this box. And also need to search in both of these properties. I looked at documentation, but there is nothing about it.

I try this

<DataTemplate x:Key="CustomerItemTemplate">
<Grid>
<StackPanel Grid.Column="1" Margin="10,0,0,0" Orientation="Horizontal">
<TextBlock Text="{Binding CustomerNo}" Style="{StaticResource ItemTextStyle}" TextWrapping="NoWrap" FontSize="20"  >
 </TextBlock>
 <TextBlock Text="{Binding Name}" Style="{StaticResource ItemTextStyle}" TextWrapping="NoWrap" FontSize="20" Margin="20,0,0,0"  />
 </StackPanel>
 </Grid>
 </DataTemplate>

In code is used:

<Input:RadAutoCompleteBox x:Name="customerCombo" Watermark="Select Customer" Margin="0" Height="50" SelectionChanged="CustomerAutoSelect" FilterMode="Contains" Padding="10,10,10,0" FontSize="18" ItemTemplate="{StaticResource CustomerItemTemplate}" />

But it crash application. At normal ComboBox it works.

Thank You for Answer.
Vlada

3 Answers, 1 is accepted

Sort by
0
Accepted
Rosy Topchiyska
Telerik team
answered on 20 Sep 2013, 11:49 AM
Hello Simon,

Thank you for your question.

To change the content template of the suggestion items you have to define an implicit Style that targets the SuggestionItem type. I have prepared a runnable sample application that demonstrates how to achieve this. I have used the default style with only  the ContentTemplate of the ContentPresenter for the SuggestionItem replaced. Thus only the content of the suggestion items is affected. You can use this style and further modify it to fulfill your requirements.

Note that you will have to initialize an instance of the PaletteInitializer class before you can use the predefined Telerik brushes.

I hope this helps. Please, let us know if we can help you any further.

Regards,
Rositsa Topchiyska
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Simon
Top achievements
Rank 1
answered on 22 Sep 2013, 10:04 PM
Hello Rositsa,

Thank you very much for your help and sample. Could you please help me how to also search in more than one property of class.

I have Customer class and I need search in CustomerNumber and CustomerName, both are string values.

Thanks
0
Rosy Topchiyska
Telerik team
answered on 24 Sep 2013, 08:33 AM
Hello Simon,

Thank you for the question.

You can use the FilterMemberProvider to provide a key to be used when filtering the suggestion items. In the passed delegate you can return a concatenation of the properties you wish to include while filtering.

If you wish to completely customize the filtering, then you can implement your own search provider. You have to inherit the TextSearchProvider defined in the Telerik.UI.Xaml.Controls.Input.AutoCompleteBox namespace and override its methods. Then you have to call the InitializeSuggestionsProvider method of the AutocompleteBox with your custom search provider as a parameter.

I hope this was useful and let us know if you need further assistance.

Regards,
Rositsa Topchiyska
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
AutoCompleteBox for XAML
Asked by
Simon
Top achievements
Rank 1
Answers by
Rosy Topchiyska
Telerik team
Simon
Top achievements
Rank 1
Share this question
or