Skip to content

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

Description

@lardecristo

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."

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions