Hi EstebanPeralta-6089,
Welcome to our Microsoft Q&A platform!
You only need to subscribe to event "Click" of the ImageButton and set its "IsVisible" property to false.
MainPage.xaml
<ImageButton HorizontalOptions="Center" VerticalOptions="CenterAndExpand"
Source="edit.png" Clicked="ImageButton_Clicked" />
MainPage.xaml.cs
private void ImageButton_Clicked(object sender, EventArgs e)
{
(sender as ImageButton).IsVisible = false;
}
---
Besides, I prefer to use MVVM to achieve it. You can refer to the following demo.
MainPage.xaml
<ContentPage.BindingContext>
<loacl:MainPageViewModel/>
</ContentPage.BindingContext>
<StackLayout>
<ImageButton HorizontalOptions="Center" VerticalOptions="CenterAndExpand"
Source="edit.png" Command="{Binding ClickCommand}" IsVisible="{Binding ShowImage}"/>
</StackLayout>
MainPageViewModel.cs
class MainPageViewModel : INotifyPropertyChanged
{
public ICommand ClickCommand { get; set; }
public MainPageViewModel()
{
ClickCommand = new Command(Click);
}
bool showImage = true;
public bool ShowImage
{
get => showImage;
set
{
showImage = value;
OnPropertyChanged("ShowImage");
}
}
void Click()
{
ShowImage = false;
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
var handle = PropertyChanged;
if(handle != null)
{
handle(this, new PropertyChangedEventArgs(propertyName));
}
}
}
Regards,
Kyle
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.