Issue
<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>
Why is there no event to clear 'SearchBar'
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/searchbar
The scenario being the user types a product into the searchBar which they select and add to the cart. Then user clicks on cart, changing from products page to SC page. However, user then changes their mind and returns to product page to change their order.
When this happens, previous text entered in SearchBar will still be displayed. I have tried SearchBar.Text = String.Empty;
on the OnDisappearing(), but that just sets the text to empty and for some reason the products page then stops working, I cant scroll up and down the LV when I try this.
Also tried SearchBar.Text = String.Empty; SearchBar.Unfocus();
but that didnt work either,
what about
SearchBar.ClearValue(what am I meant to put here? when I am only accessing it from..
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?
}
am I mssing something? shouldnt there be something along the lines of SearchBar.Clear()?
thank you
Solution
have you tried to use this:
protected override void OnAppearing()
{
base.OnAppearing();
SearchBar.Text = ""; //<<-- add this
}
also makes sure in SearchBar_TextChanged
if (!String.IsNullOrWhiteSpace(SearchBar.Text))
{
//this code will be executed when there's a text in searchbar
}
Answered By - Godya Aditya
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.