Xamarin.Forms icon indicating copy to clipboard operation
Xamarin.Forms copied to clipboard

[Bug] Button self-bound height request to width doesn't work within a CollectionView

Open sjordanGSS opened this issue 3 years ago • 0 comments

Description

Using the following code:

                    <CollectionView FlexLayout.Grow="1">
                        <CollectionView.ItemsSource>
                            <x:Array Type="{x:Type x:String}">
                                <x:String>item</x:String>
                            </x:Array>
                        </CollectionView.ItemsSource>

                        <CollectionView.ItemTemplate>
                            <DataTemplate>
                                <Button HeightRequest="{Binding Source={RelativeSource Mode=Self}, Path=Width}"/>
                            </DataTemplate>
                        </CollectionView.ItemTemplate>
                    </CollectionView>

The height of the button is not affected by the binding.

Triggering a XAML Hot Reload causes the button to be sized correctly.

Steps to Reproduce

Reproduction available here: https://github.com/sjordanGSS/popupCarouselCollectionViewHeight

Note that there is some commented code in MainPage.xaml that when uncommented will place the CollectionView in a CarouselView, and will display a button that opens a Xamarin.CommunityToolkit popup containing the same views. They each act a little bit differently: scrolling the CarouselView will cause the buttons to size correctly after a few swipes, while the Popup will size the first button correctly but not the second.

Expected Behavior

Button should appear square as the height is bound to it's own width

Actual Behavior

Button is not square

Basic Information

  • Version with issue: Observed in 5.0.0.2512
  • Last known good version: Not Tested
  • Platform Target Frameworks:
    • iOS: not tested
    • Android: 13
    • UWP: not tested
  • Android Support Library / AndroidX Version:
  • NuGet Packages:
    • Xamarin.Forms 5.0.0.2512
    • Xamarin.CommunityToolkit 2.0.4
  • Affected Devices: Tested on Android 7.1

Environment

Show/Hide Visual Studio info

Build Logs

Screenshots

Reproduction Link

https://github.com/sjordanGSS/popupCarouselCollectionViewHeight

Workaround

If you toggle the visibility of the control in question (in this case the button) it'll be redrawn with the correct size. I've added this to the repro in the branch "toggle-visible-fix-measure", where clicking on the button will toggle its visibility. I've verified that this works on Android 13 and 7.1.

sjordanGSS avatar Sep 02 '22 16:09 sjordanGSS