微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

xamarin 表单 - 清除 SearchBar

如何解决xamarin 表单 - 清除 SearchBar

<NavigationPage.TitleView>
                <StackLayout BackgroundColor="Red" HorizontalOptions="FillAndExpand" VerticalOptions="StartAndExpand" Orientation="Horizontal">
                    <SearchBar x:Name="SearchBar" BackgroundColor="#brown" TextChanged="SearchBar_TextChanged" HorizontalOptions="FillAndExpand" Placeholder="Search..." PlaceholderColor="Gray" TextColor="White" VerticalOptions="StartAndExpand"/>
                </StackLayout>
            </NavigationPage.TitleView> 

为什么没有清除“SearchBar”的事件

https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/searchbar

该场景是用户将产品输入到他们选择并添加到购物车的搜索栏中。然后用户点击购物车,从产品页面切换到 SC 页面。但是,用户随后改变主意并返回产品页面更改订单。

发生这种情况时,仍会显示之前在 SearchBar 中输入的文本。 我努力了 SearchBar.Text = String.Empty;

在 Ondisappearing() 上,但这只是将文本设置为空,然后由于某种原因产品页面停止工作,当我尝试此操作时,我无法上下滚动 LV。

也试过了 SearchBar.Text = String.Empty; SearchBar.Unfocus();

但这也没有用,

怎么样

SearchBar.ClearValue(我想放在这里是什么?当我只从...访问它时..

 protected override void Ondisappearing()
        {       
//would this resolve it?
            SearchBarControl.ClearValue(//how do I access bindable property that it is asking for? when its not an event callback?
       
        }

我是在说些什么吗?不应该有类似 SearchBar.Clear() 的东西吗?

谢谢

解决方法

你有没有试过使用这个:

protected override void OnAppearing()
    {
        base.OnAppearing();
        SearchBar.Text = "";  //<<-- add this
    }

也在 SearchBar_TextChanged 中确保

if (!String.IsNullOrWhiteSpace(SearchBar.Text)) 
    {
        //this code will be executed when there's a text in searchbar
    }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。