Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The IsVisible property is not working for Images or ImageButtons in Android #27352

Open
FANMixco opened this issue Jan 25, 2025 · 2 comments
Open
Labels
s/needs-repro Attach a solution or code which reproduces the issue t/bug Something isn't working

Comments

@FANMixco
Copy link

FANMixco commented Jan 25, 2025

Description

I have an ImageButton in an app, I need to hide it or show it conditionally:

<ImageButton x:Name="previewImage"
	HeightRequest="48"
	WidthRequest="48"
	Aspect="AspectFill"
	Source="{Binding PreviewImageSource}"
	IsVisible="{Binding IsPreviewVisible}"
	Clicked="OnDeleteClicked"
	BackgroundColor="Transparent" />

The Source is working perfectly, but the image stays visible even if I set a static value in the IsVisible property:

private bool _isPreviewVisible;
public bool IsPreviewVisible
{
	get => _isPreviewVisible;
	set
	{
		_isPreviewVisible = value;
		OnPropertyChanged(nameof(IsPreviewVisible));
	}
}

public void UpdatePreviewImage()
{
	IsPreviewVisible = false;
	/*string folderPath = Path.Combine(FileSystem.AppDataDirectory, "Downloads");
	var imagePaths = Directory.GetFiles(folderPath, "*.jpg").ToList();

	if (imagePaths.Count > 0)
	{
		PreviewImageSource = imagePaths.First(); // Set the latest image
		IsPreviewVisible = true;
	}
	else
	{
		PreviewImageSource = null; // Clear the image source
		IsPreviewVisible = false; // Hide the button
	}*/
}

public event PropertyChangedEventHandler PropertyChanged;

protected virtual void OnPropertyChanged(string propertyName)
{
	PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

The issue only happens with the Images or ImageButtons since I am binding also a button and works perfectly well:

<Button ImageSource="trash_can.png"
        WidthRequest="48"
        HeightRequest="48"
        Clicked="OnDeleteClicked"
        IsVisible="{Binding IsDeleteButtonVisible}"/>

Any idea why this is failing? Thanks.

Steps to Reproduce

  1. Add an ImageButton or Image.
  2. Bind the Visible property to false.

Link to public reproduction project repository

No response

Version with bug

9.0.30 SR3

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android, I was not able test on other platforms

Affected platform versions

Android

Did you find any workaround?

No response

Relevant log output

@FANMixco FANMixco added the t/bug Something isn't working label Jan 25, 2025
Copy link

We've found some similar issues:

If any of the above are duplicates, please consider closing this issue out and adding additional context in the original issue.

Note: You can give me feedback by 👍 or 👎 this comment.

@FANMixco FANMixco changed the title Visible is not working for Images or ImageButtons in Android The IsVisible property is not working for Images or ImageButtons in Android Jan 25, 2025
@kubaflo
Copy link
Contributor

kubaflo commented Jan 26, 2025

Hi I cannot replicate it

public class MainPageViewModel : System.ComponentModel.INotifyPropertyChanged
{
	private bool _isPreviewVisible;
	public bool IsPreviewVisible
	{
		get => _isPreviewVisible;
		set
		{
			_isPreviewVisible = value;
			OnPropertyChanged();
		}
	}

	private string _previewImageSource = "dotnet_bot.png";
	public string PreviewImageSource
	{
		get => _previewImageSource;
		set
		{
			_previewImageSource = value;
			OnPropertyChanged();
		}
	}

	public event System.ComponentModel.PropertyChangedEventHandler? PropertyChanged;

	protected void OnPropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string? propertyName = null)
	{
		PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
	}

	public Command ToggleVisibilityCommand => new Command(() => IsPreviewVisible = !IsPreviewVisible);
}

Could you please attach a repo?

@kubaflo kubaflo added the s/needs-repro Attach a solution or code which reproduces the issue label Jan 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s/needs-repro Attach a solution or code which reproduces the issue t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants