CarouselView is consuming all vertical space in my layout, unless I give it a size. But I don't know the height to give it b/c I want it to size to my content. Please let me size to my content, either the height or the width perhaps?
<StackLayout Margin="15">
<Frame BackgroundColor="White"
Padding="10"
BorderColor="Black"
CornerRadius="0">
<CarouselView>
<CarouselView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>rei_01.jpg</x:String>
<x:String>rei_02.jpg</x:String>
<x:String>rei_03.jpg</x:String>
<x:String>rei_04.jpg</x:String>
</x:Array>
</CarouselView.ItemsSource>
<CarouselView.ItemTemplate>
<DataTemplate>
<Image Source="{Binding .}"/>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
</Frame>
</StackLayout>
CarouselView sizes to my content and provides a consistent layout across different screen sizes.
CarouselView consumes ALL space in the layout, even pushing other layouts out of view. I have to set a height to achieve the results I want on this screen, but it will look wrong on other sizes screens.
All consuming height:
Fixed height (guessing):
Confirmed that this is happening. Tried a couple of different things to make it size to content, but it seems to always take the full available height. Happens on Android.
On iOS is NREs altogether, stack trace is below. Not sure it it's related to this though. iOS error seems more of an Shell issue
at System.Reflection.RuntimeConstructorInfo.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) [0x00018] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:944
at System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic, System.Boolean wrapExceptions) [0x00095] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/corlib/ReferenceSources/RuntimeType.cs:185
at System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean wrapExceptions, System.Boolean skipCheckThis, System.Boolean fillCache) [0x00009] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/corlib/ReferenceSources/RuntimeType.cs:155
at System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Boolean wrapExceptions, System.Threading.StackCrawlMark& stackMark) [0x00027] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/referencesource/mscorlib/system/rttype.cs:5770
at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic, System.Boolean wrapExceptions) [0x00039] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/referencesource/mscorlib/system/activator.cs:206
at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) [0x00000] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/referencesource/mscorlib/system/activator.cs:190
at System.Activator.CreateInstance (System.Type type) [0x00000] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/referencesource/mscorlib/system/activator.cs:134
at Xamarin.Forms.ElementTemplate+<>c__DisplayClass4_0.<.ctor>b__0 () [0x00000] in d:agent1sXamarin.Forms.CoreElementTemplate.cs:26
at Xamarin.Forms.ElementTemplate.CreateContent () [0x00031] in d:agent1sXamarin.Forms.CoreElementTemplate.cs:82
at Xamarin.Forms.Internals.DataTemplateExtensions.CreateContent (Xamarin.Forms.DataTemplate self, System.Object item, Xamarin.Forms.BindableObject container) [0x00001] in d:agent1sXamarin.Forms.CoreDataTemplateExtensions.cs:19
at Xamarin.Forms.ShellContent.Xamarin.Forms.IShellContentController.GetOrCreateContent () [0x00036] in d:agent1sXamarin.Forms.CoreShellShellContent.cs:61
at Xamarin.Forms.Platform.iOS.ShellSectionRootRenderer.LoadRenderers () [0x00024] in d:agent1sXamarin.Forms.Platform.iOSRenderersShellSectionRootRenderer.cs:145
at Xamarin.Forms.Platform.iOS.ShellSectionRootRenderer.ViewDidLoad () [0x0003b] in d:agent1sXamarin.Forms.Platform.iOSRenderersShellSectionRootRenderer.cs:63
at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.8.2.2/src/Xamarin.iOS/UIKit/UIApplication.cs:86
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.8.2.2/src/Xamarin.iOS/UIKit/UIApplication.cs:65
at CarouselGallery.iOS.Application.Main (System.String[] args) [0x00001] in /Users/jfversluis/Downloads/CarouselGallery-master/CarouselGallery/CarouselGallery.iOS/Main.cs:17
@rmarinho
Ping. Any progress on this? With this bug CarouselView is unusable.
After talking with @ez I think this a issue we need to look also with CollectionView , we will see how to fix this.
As a work-around it works if you put it into a stacklayout
As a work-around it works if you put it into a stacklayout
But in the sample code of @davidortinau the CarouselView is already placed inside a StackLayout. How is your workaround supposed to work?
@samhouts Is there any progress on this? Quite a big issue for me atm
I would love to see a fix for this as well.
Looking forward to seeing this issue fixed for CollectionView. Sounds like the space issues with both are being addressed at the same time. Just spent a bunch of time trying to figure out why my layout, which includes two CollectionViews, wasn't laying out like I expected.
Open 24 Nov 2019... any news ?
@samhouts
With this bug the CarouselView is unusable. Is this ever going to be fixed?
Xamarin team, these components can not be used in a production environment right now. This issue has been open since late 2019. What is happening? If they are broken and will not get fixed, please obsolete them to let developers know, instead of letting them waste time on something that will ultimately not work. It鈥檚 better if they are obsoleted as then the expectation will be that they might not work or get fixed.
Thanks!
Just so you know, a very dirty hack that subscribes to element view size changes can be used to manually set the CollectionView's Height appropriately, if you absolutely need to use the CollectionView. But I too would like to see this working out of the box. :)
Meanwhile I'm writing so much workaround code for bugs like this that the whole cross-platform advantage is melting down... I used a fixed HeightRequest on the CarouselView to avoid infinite height sizing, but - as you can assume - this causes new troubles.
Any word on this? Every time I want to use a CollectionView or CarouselView I get burned by this issue and have to resort to customer repeaters or bindable layouts. It's disappointing that this has not been given high priority especially since CollectionView is out of Preview.
Please fix this, this is affecting a lot, I have a collection view and a carousel view in the same page and this is killing me..
Yeah I'm having the same problem here
Has anyone found a workaround for this issue?
Most helpful comment
Meanwhile I'm writing so much workaround code for bugs like this that the whole cross-platform advantage is melting down... I used a fixed HeightRequest on the CarouselView to avoid infinite height sizing, but - as you can assume - this causes new troubles.