Hello,
is it possible in the entry field when the user tap the x to clear the entry content to display a pop-up that ask something like OK Cancel. so to prevent accidentally tapping x.
Yes, we can set ClearButtonVisibility="Never" and add clear button to cover the Entry by Gird.
If you have deleted icon, you can use Imagebutton as well. I set the Button's background to Transparent and set HorizontalOptions="End"
.
<Grid>
<Entry
x:Name="MyEntry"
FontSize="14"
ClearButtonVisibility="Never"
HeightRequest="35"
HorizontalOptions="FillAndExpand"
TextChanged="MyEntry_TextChanged"
Text="test"
VerticalOptions="FillAndExpand"/>
<Button x:Name="deleteIconButton"
Margin="0,0,-10,0"
IsVisible="False"
FontSize="16"
Text="X"
HorizontalOptions="End"
TextColor="Black"
Background="Transparent"
Clicked="Button_Clicked"/>
</Grid>
When you click the button, it will pop up an Alert to ask user, if delete content, if yes, clear the text, if no, do not make any operations. If you want to hide the delete icon, I detect the text change event, if the text is null, hide the delete icon. If you want the delete icon always show, just remove all content about deleteIconButton.IsVisible = false;
in button click event and TextChanged="MyEntry_TextChanged"
private async void Button_Clicked(object sender, EventArgs e)
{
bool answer = await DisplayAlert("warning?", "Would you want to delete this text", "Yes", "No");
if (answer) {
MyEntry.Text = "";
deleteIconButton.IsVisible = false;
}
}
private void MyEntry_TextChanged(object sender, TextChangedEventArgs e)
{
Entry entry = sender as Entry;
if (entry.Text != null && deleteIconButton != null)
{
deleteIconButton.IsVisible = true;
}
else if (deleteIconButton != null)
{
deleteIconButton.IsVisible = false;
}
}
I tried to use handler to implement it, but MAUI do not have Api to get the delete icon, we have to re-implement this delete icon as well for different platforms.
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
**Note: Please follow the steps in our [documentation](https://docs.microsoft.com/en-us/ans