Xamarin.forms 搜索栏和Xamarin.Form

Xamarin.forms 搜索栏和Xamarin.Form,xamarin.forms,Xamarin.forms,我正在做一个XF项目,它有一个搜索栏。XAML声明如下所示 <SearchBar Placeholder="Result" Text="{Binding SearchedCustomer,Mode=TwoWay}" SearchCommand="{Binding SearchCustomerCommand}"></SearchBar> 当我在搜索栏中键入时,SearchedCustomer字段会发生更改,但是searcheccustom

我正在做一个XF项目,它有一个搜索栏。XAML声明如下所示

<SearchBar Placeholder="Result" Text="{Binding SearchedCustomer,Mode=TwoWay}" 
                SearchCommand="{Binding SearchCustomerCommand}"></SearchBar>
当我在搜索栏中键入时,SearchedCustomer字段会发生更改,但是searcheccustomercommand命令不会执行


有人能帮我确定我做错了什么吗?

如果我没有弄错,只有在按下“完成/返回”按钮时,命令才会启动Hanks Gerald。我的印象是,它会在击键时被调用。嗨,Gerald,正如你提到的那样,这确实有效,但是,一旦搜索命令成功执行,应用程序似乎就会崩溃。你似乎没有初始化
CustomerList
objectHi Gerald。事实上,在CustomerList属性中调用的FillCustomerDetails()函数负责填充它。当我在点击搜索栏中的enter键后进行调试时,我可以看到在ExecuteSearchCustomerCommand方法中填充的结果,但是一旦函数存在,应用程序就会崩溃。
    private string _SearchedCustomer;
    public string SearchedCustomer
    {
        get { return _SearchedCustomer; }
        set { SetProperty(ref _SearchedCustomer, value); }
    }

    public DelegateCommand SearchCustomerCommand { get; set; }

    private ObservableCollection<CustomerModel> _CustomerList;
    public ObservableCollection<CustomerModel> CustomerList
    {
        get
        {
            if (_CustomerList == null)
                FillCustomerDetails();
            return _CustomerList;
        }
        set { SetProperty(ref _CustomerList, value); }
    }

    private void ExecuteSearchCustomerCommand()
    {
        var tempRecords = _CustomerList.Where(c => c.ReferenceText.Contains(SearchedCustomer));
        CustomerList.Clear();
        foreach (var item in tempRecords)
        {
            CustomerList.Add(item);
        }
    }
SearchCustomerCommand = new DelegateCommand(ExecuteSearchCustomerCommand).ObservesProperty(()=> SearchedCustomer);