I have a custom implemented control which is very memory intensive (it basically displays a group header and an accordionControl for each group). The CustomControls AccordionControlGrouping and AccordionControl both inherit from StackLayout, so I have implemented my own bindable ItemsSource. I actively change the views of the controls when the ItemsSource changes. I have optimized this change now (using LINQ and BinarySearch and that stuff) to get from 5sec. per search to 0.8sec.
This wouldn't be a problem per se, but each time a user enters a key the keyboard freezes and is therefore very unconvinient to search.
My SearchBar is bound to the command of a ViewModel like this
<SearchBar x:Name="EventSearchBar"
Text="{Binding SearchText}"
SearchCommand="{Binding SearchCommand}"
Placeholder="Suche"/>
SearchCommand
private Xamarin.Forms.Command _searchCommand;
public System.Windows.Input.ICommand SearchCommand
{
get
{
_searchCommand = _searchCommand ?? new Xamarin.Forms.Command(UpdateAccordionControlGrouping, CanExecuteSearchCommand);
return _searchCommand;
}
}
private bool CanExecuteSearchCommand()
{
return true;
}
SearchText Property
private string _searchText = string.Empty;
public string SearchText
{
get { return _searchText; }
set
{
if (_searchText != value)
{
_searchText = value ?? string.Empty;
RaisePropertyChanged(nameof(SearchText));
// Perform the search
if (SearchCommand.CanExecute(null))
SearchCommand.Execute(null);
}
}
}
UpdateAccordionControlGrouping
private void UpdateAccordionControlGrouping()
{
// Do some LINQ stuff to group and filter a global collection of data.
// And raise the #OnPropertyChanged event for the ItemsSource of my
// custom control.
}
Now how do I make this whole process async?
I have already looked into this article and it didn't work for me.