Mallow
Mallow

Reputation: 3

Hide button after it was clicked

I would like to hide a button after it was clicked but I don't know how.

C#

private async void btn1Clicked(object sender, EventArgs e)
{
    if (condition)
    {
        // hide button
    }
}

XAML

<Button Clicked="btn1Clicked"/>

Upvotes: 0

Views: 2961

Answers (2)

Dorin Baba
Dorin Baba

Reputation: 1738

You can do the following

private async void btn1Clicked(object sender, EventArgs e)
{
    Button btn = (Button)sender;

    if(condition)
    {
        // hide the button
        btn.IsVisible = false;
        
        // or disable the button. 
        // As Caius Jard said, disappearing buttons sometimes cause confusion.
        btn.IsEnabled = false; 
    }   
}

Upvotes: 0

iamdlm
iamdlm

Reputation: 1983

If you want to make your button invisible you can do:

if (condition)
{
    button.Visibility=ViewStates.Invisible;
}
else
{
    button.Visibility=ViewStates.Visible;
}

Or you can use IsVisible property.

Upvotes: 1

Related Questions