-1

I am using carousel view to display images. If I have the device on portrait then everything is ok however once I change to landscape the current picture is cut a bit but once I swipe to the next picture it recalculates and is all ok. / using iOS

Back of the page

 protected override void OnSizeAllocated(double width, double height)
        {
            base.OnSizeAllocated(width, height);
            if (width != this.width || height != this.height)
            {
                this.width = width;
                this.height = height;
                if (width > height)
                {
                   
                    carousel.HorizontalOptions = LayoutOptions.CenterAndExpand;
                    carousel.VerticalOptions = LayoutOptions.CenterAndExpand;
                    outerStack.HeightRequest = 1700;
                   
               
                }
                else
                {
                    carousel.HorizontalOptions = LayoutOptions.CenterAndExpand;
                    carousel.VerticalOptions = LayoutOptions.CenterAndExpand;
                    outerStack.HeightRequest = 800;
                }
            }
        }

Can you advise plea what am I doing wrong?

RD JT
  • 65
  • 6
  • 1
    Does this answer your question? [Styling depending on screen orientation in Xamarin forms](https://stackoverflow.com/questions/66099930/styling-depending-on-screen-orientation-in-xamarin-forms) – Cfun Feb 13 '21 at 12:55
  • this really didn't help, plus the visual state trigger didn't work, I have tried it exactly how it is not git hub in example but color didn't change, but thank for taking the time – RD JT Feb 14 '21 at 10:51
  • Something is missing because I tested before I post the answer and it is working, do you have auto-rotate enabled? I mean the example is for the Grid didn't test on CarousselView yet – Cfun Feb 14 '21 at 10:54
  • Could you provide a screenshot or two to illustrate the issue ? What are you trying to achieve in `OnSizeAllocated`? – Cfun Feb 14 '21 at 11:09
  • when on size get called every time I turn the device. This works, what I was trying to explain in my question was that the picture is sometimes cut until a scroll to the next picture. I have tried it with your posted answer and then from GitHub unfotunally I was not able to make it work. I tried it only on simulator and on iOS – RD JT Feb 14 '21 at 16:31
  • I can't I am new member and because my question got -1 and was closed I can't even ask more questions:) – RD JT Feb 14 '21 at 16:31

1 Answers1

0

Seems to be an open issue with the CarouselView

There's a comment in there by nate123456

I'm having this problem as well in iOS. It seems that setting the CarouselView as the ContentPage.Content is the only scenario that I have been able to find that actually enables the CarouselView to correctly adjust when rotation occurs.

Ultimately we decided to just remove the Indicator View since that was proving problematic on iOS anyway. It's still experimental after all.

Hope this helps! If and when this is resolved please someone update us all :)