RadAutoSuggestBox with WPF MVVM

1 Answer 236 Views
AutoSuggestBox
M
Top achievements
Rank 1
M asked on 30 Sep 2022, 06:27 AM

Hi All,

I am trying to explore RadAutoSuggestBox (R2 2022 SP1 version) in my WPF MVVM application however I didn't find any support, how to purely bind (TextChanged event and few others) it with my ViewModel. My requirement is: Whenever user type, I have to make API call and then bind response with control's itemsource.

Any help will be appreciated.

1 Answer, 1 is accepted

Sort by
0
Stenly
Telerik team
answered on 04 Oct 2022, 08:31 AM

Hello M Irfan,

What I could suggest in this scenario would be to use the EventToCommandBehavior. Using it, the TextChanged event could be bound to a command from your view model, which will be fired every time the event occurs. This will allow you to not have any code-behind and to keep a clean MVVM structure.

The following code snippet shows how to use the EventToCommandBehavior:

<telerik:RadAutoSuggestBox x:Name="autoSuggestBox">
    <telerik:EventToCommandBehavior.EventBindings>
        <telerik:EventBinding EventName="TextChanged" Command="{Binding MyCommand}" PassEventArgsToCommand="True"/>
    </telerik:EventToCommandBehavior.EventBindings>
</telerik:RadAutoSuggestBox>

For your convenience, I have prepared a sample project with the RadAutoSuggestBox that follows the MVVM pattern. The collection that is bound to the ItemsSource property of the control is updated in the command for the TextChanged event.

Regards,
Stenly
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
AutoSuggestBox
Asked by
M
Top achievements
Rank 1
Answers by
Stenly
Telerik team
Share this question
or