ImageButton Source Binding problem

AlessandroCaliaroAlessandroCaliaro ✭✭✭✭✭ITMember ✭✭✭✭✭

Hi

I am using Image Button with this code:

        ImageButton imageButtonStampa = new ImageButton() { Style = (Style)Application.Current.Resources["imageButtonStyle"] };
        imageButtonStampa.SetBinding(ImageButton.CommandProperty, "StampaCommand");
        imageButtonStampa.SetBinding(ImageButton.IsEnabledProperty, new Binding("NewBarcode", converter: new IsNotNullToBooleanConverter()));
        imageButtonStampa.SetBinding(ImageButton.SourceProperty, new Binding("NewBarcode", converter: new IsNotNullToSourceConverter(), converterParameter: stampaSources));

First time I open the page I have this:

Then I insert some data, IsNotNullToSourceConverter fires and Source changes:

Now, when I press the ImageButton, I send some data to a bluetooth printer.

        StampaCommand = new Command(async () => {
            try
            {

                if (_isTapped)
                    return;

                _isTapped = true;

                await Util.Print.PrintBarcode(Preferences.GetPrinterBarcode(), NewBarcode);

                _isTapped = false;
            }
            catch (Exception ex)
            {
                _isTapped = false;
                await Application.Current.MainPage.DisplayAlert(AppResources.Attenzione, ex.Message, AppResources.Ok);
            }
        });

But I have this problem:

and when print is finished, the problem remains:

If I rotate the screen, problem disappears:

What can I do for this?

@DavidOrtinau

Thanks
Alessandro

Answers

  • DavidOrtinauDavidOrtinau Xamurai USForum Administrator, Xamarin Team, Insider, University Xamurai

    Yikes!

    This happens when you press and Source binding is updated, correct?

    What's your imageButtonStyle?

  • AlessandroCaliaroAlessandroCaliaro ✭✭✭✭✭ ITMember ✭✭✭✭✭
    edited April 11
            var imageButtonStyle = new Style(typeof(ImageButton))
            {
                Setters =
                {
                    new Setter {Property = ImageButton.BackgroundColorProperty, Value = Color.FromHex("#951718")},
                    new Setter {Property = ImageButton.CornerRadiusProperty, Value = 10}
                }
            };
    

    Yes, Source Binding is updated correctly (Image pass from gray to blank) but correct dimension is lost

  • DavidOrtinauDavidOrtinau Xamurai USForum Administrator, Xamarin Team, Insider, University Xamurai

    I'm seeing a few other reports that ImageButton has state issues, but none match this exactly. If you would, please file a report on GitHub.

    Try setting the Aspect and see if that doesn't force the expected behavior. Workaround would be to build a custom control either with more primitive elements, or perhaps extend ImageButton and force a measure/layout pass after the binding update.

  • AlessandroCaliaroAlessandroCaliaro ✭✭✭✭✭ ITMember ✭✭✭✭✭

    @DavidOrtinau said:
    I'm seeing a few other reports that ImageButton has state issues, but none match this exactly. If you would, please file a report on GitHub.

    Try setting the Aspect and see if that doesn't force the expected behavior. Workaround would be to build a custom control either with more primitive elements, or perhaps extend ImageButton and force a measure/layout pass after the binding update.

    Understand. I try to find the time to put something on GitHub. Thanks @DavidOrtinau

Sign In or Register to comment.