SearchHandler.OnQueryChanged(String, String) 方法

定義

開發人員可以覆寫這個方法以回應修改 Query

protected virtual void OnQueryChanged (string oldValue, string newValue);
abstract member OnQueryChanged : string * string -> unit
override this.OnQueryChanged : string * string -> unit

參數

oldValue
System.String
newValue
System.String

備註

常見的使用案例是在使用者輸入數據時修改一組建議:

protected override void OnQueryChanged(string oldValue, string newValue)
{
    base.OnQueryChanged(oldValue, newValue);
    if (string.IsNullOrWhiteSpace(newValue))
    {
        ItemsSource = null;
    }
    else
    {
        ItemsSource = MonkeyData.Monkeys
            .Where(monkey => monkey.Name.ToLower().Contains(newValue.ToLower()))
            .ToList<Animal>();
    }
}

適用於