dotMorten / MauiEx

A set of .NET MAUI controls
Apache License 2.0
225 stars 55 forks source link

Not able to get Text value and fill ItemsSource when trying to implement MVVM #88

Open lardecristo opened 3 years ago

lardecristo commented 3 years ago

I try get Text value in my MVVM. I think I have this problem, because I don't get the object AutoSuggestBox when I use Behaviors. I receive this AutoSuggestBoxTextChangedEventArgs object , but not AutoSuggestBox object.

In your example, you use code-behind.

Your example

`private async void dynamicSuggestBox_TextChanged(object sender, dotMorten.Xamarin.Forms.AutoSuggestBoxTextChangedEventArgs args) {

AutoSuggestBox box = (AutoSuggestBox)sender; // Only get results when it was a user typing, // otherwise assume the value got filled in by TextMemberPath // or the handler for SuggestionChosen. if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput) { if (string.IsNullOrWhiteSpace(box.Text) || box.Text.Length < 3) box.ItemsSource = null; else { var suggestions = await GetSuggestions(box.Text); box.ItemsSource = suggestions.ToList(); } } }`

I like the same code, but in MVVM pattern.

"I still learning English."