【发布时间】:2021-05-06 19:30:59
【问题描述】:
<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() 的东西吗?
谢谢
【问题讨论】:
-
只需设置
searchBar.Text = string.Empty;。如果这导致代码中的其他地方出现问题,请解决该问题。 -
肯定的....
标签: c# xaml xamarin xamarin.forms searchbar