【发布时间】:2018-12-25 21:56:26
【问题描述】:
我正在尝试使用作为 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 docs 提到了搜索处理程序,但它们并未包含有关如何使用它的任何详细信息,并且示例应用程序仅演示了填充建议。
有没有人提供关于我应该如何通知我的 ContentPage 我的 SearchHandler 确认搜索的指针?
【问题讨论】:
-
github.com/xamarin/Xamarin.Forms/blob/master/…你可以参考这个demo。
-
感谢@LucasZhang-MSFT,但我没有看到该示例中正在处理搜索确认事件。它只是调用基类方法。是否发生了一些神奇的约定处理?
标签: xamarin.forms xamarin-forms-4