xamarin.forms - 将搜索词从 SearchHandler 传递到 Xamarin Forms 4 中的 ContentPage
问题描述
我正在尝试使用作为 Xamarin Forms 4 的一部分实现的新 SearchHandler。到目前为止,我发现获取建议非常容易,但现在我想引发一个事件,或者遵循建议的处理方法确认搜索。
public class FoodSearchHandler: SearchHandler
{
IFoodDataStore dataStore = new FoodDataStore();
protected override void OnQueryConfirmed()
{
base.OnQueryConfirmed();
// What to do here?
}
protected override void OnQueryChanged(string oldValue, string newValue)
{
base.OnQueryChanged(oldValue, newValue);
if(!string.IsNullOrWhiteSpace(newValue)
{
// Populate suggestions
ItemsSource = dataStore.GetSuggestions(newValue);
}
else
{
ItemsSource = null;
}
}
}
public partial class FoodsPage : ContentPage
{
ObservableCollection<Food> Foods = new ObservableCollection<Food>();
public ItemsPage()
{
InitializeComponent();
// Wire up the search handler
Shell.SetSearchHandler(this, new FoodSearchHandler());
BindingContext = this;
}
}
不幸的是,尽管alpha 文档提到了搜索处理程序,但它们没有包含有关如何使用它的任何详细信息,并且示例应用程序仅演示了填充建议。
有没有人可以提供关于我应该如何通知我的 ContentPage 我的 SearchHandler 确认搜索的指针?
解决方案
因此,在阅读了更多 Shell 文档之后,似乎我在这种情况下想要做的是使用 Shell 的新导航并导航到将搜索文本作为查询传递的路由,例如:
protected override void OnQueryConfirmed()
{
base.OnQueryConfirmed();
var shell = Application.Current.MainPage as Shell;
shell.GoToAsync($"app:///fructika/search?query={Query}", true);
}
注意:现在传递数据似乎不起作用,或者如果确实如此,我做错了,但我会提出一个单独的问题。
推荐阅读
- javascript - 排序/过滤库“查看全部”不起作用
- reactjs - React hook 依赖函数作为 props
- angular - ngIf 的工作原理是否比隐藏属性快得多?
- matlab - Newton-Raphson 实施的说明
- android - 如何检查密钥是否已存在于firebase中
- mongodb - mongodb:预烘焙 conf 文件以启动副本集
- django - 带有 GET 请求的 Django DeleteView
- python - python树数据结构的打印问题
- xaml - .cs 文件不在 .xaml 文件下
- ubuntu - 在不同的基于 linux 的操作系统中构建