flower-story/FlowerApp/Controls/ItemSearchHandler.cs
2023-07-31 17:11:39 +08:00

35 lines
958 B
C#

using Blahblah.FlowerApp.Controls;
using static Blahblah.FlowerApp.Extensions;
namespace Blahblah.FlowerApp;
public class ItemSearchHandler : SearchHandler
{
public static readonly BindableProperty FlowersProperty = CreateProperty<FlowerClientItem[], ItemSearchHandler>(nameof(Flowers));
public FlowerClientItem[] Flowers
{
get => (FlowerClientItem[])GetValue(FlowersProperty);
set => SetValue(FlowersProperty, value);
}
protected override void OnQueryChanged(string oldValue, string newValue)
{
base.OnQueryChanged(oldValue, newValue);
if (string.IsNullOrWhiteSpace(newValue))
{
ItemsSource = null;
}
else
{
ItemsSource = Flowers?.Where(f => f.Name.Contains(newValue, StringComparison.OrdinalIgnoreCase)).ToList();
}
}
protected override void OnItemSelected(object item)
{
base.OnItemSelected(item);
}
}