【发布时间】:2020-08-15 05:42:30
【问题描述】:
我有一个简单的 search-bar 组件及其 TextChanged 事件
<SearchBar x:Name="SearchBar" Placeholder="Search words..."
CancelButtonColor="Black"
TextColor="Black"
PlaceholderColor="Black"
BackgroundColor="Transparent"
FontSize="Medium"
TextChanged="SearchBar_TextChanged"
/>
在SearchBar_TextChanged() 方法中,我尝试通过文本查找数据并将其分配给项目源。一切正常,但问题是搜索栏在过滤后没有焦点。
private async void SearchBar_TextChanged(object sender, TextChangedEventArgs e)
{
if (string.IsNullOrWhiteSpace(e.NewTextValue))
words.ItemsSource = await wordRepository.GetAllAsync();
else
words.ItemsSource = await wordRepository.Find(x => x.Name.ToLower().Contains(e.NewTextValue.ToLower()));
}
【问题讨论】:
标签: c# xamarin.forms xamarin.android searchbar