Need to create textchanged for searchbar in Viewmodel?

Sowndarrajan Vijayaragavan 450 Reputation points
2024-03-13T17:29:34.3+00:00

My workaround:

xaml:

<SearchBar
                            x:Name="SearchBar"
                           
                            TextChanged="SearchBar_TextChanged"
                            SearchCommand="{Binding SearchCommand}"
                            SearchCommandParameter="{Binding Source={x:Reference SearchBar}, Path=Text}" />

c#:

private void SearchBar_TextChanged(object sender, TextChangedEventArgs e)
        {
        }


Currently i can able to create a textchanged in .cs

I nned to acheive the same in Viewmodel. When the text is changed it should trigger in the ViewModel.

Developer technologies | .NET | .NET MAUI
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2024-03-14T02:57:14.3366667+00:00

    Hello,

    SearchBar_TextChanged is an event, and for the need to call the event in the ViewModel, you need to convert the event to a Command via the EventToCommand feature of the CommunityToolkit.

    Please refer to the following documentation.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.