Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Xamarin ContentPage stop responding when CollectionView is included in ScrollView with Visible=False

iboconibocon Member ✭✭
edited September 18 in Xamarin.Forms

I stuck into vary strange issue.

I have vary simple layout like below,

<ScrollView>
    <CollectionView />
</ScrollView>

And I just changed ScrollView.IsVisible = False and then my application does not response when try to load main page on iOS device.

  • Xamarin.Forms 4.8.0.1451

XAML

    <ContentPage
        xmlns="http://xamarin.com/schemas/2014/forms"
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        xmlns:Test="clr-namespace:CollectionViewTest"
        x:Class="CollectionViewTest.MainPage">
            <ScrollView IsVisible="False">
            <CollectionView
                ItemsSource="{Binding ItemSource}"
                SelectionMode="Single">

                <CollectionView.ItemsLayout>
                    <GridItemsLayout
                        Orientation="Vertical"
                        Span="4"
                        VerticalItemSpacing="10"/>
                </CollectionView.ItemsLayout>

                <CollectionView.ItemTemplate>
                    <DataTemplate>
                        <Image
                            Source="{Test:ImageResource CollectionViewTest.waterfront.jpg}"
                            Aspect="AspectFit"
                            WidthRequest="70"
                            HeightRequest="70"/>
                    </DataTemplate>
                </CollectionView.ItemTemplate>

            </CollectionView>
        </ScrollView>
    </ContentPage>

ViewModel

    public class MainPageViewModel : INotifyPropertyChanged
    {
        private ObservableCollection<object> _itemSource;
        public ObservableCollection<object> ItemSource => _itemSource;

        public MainPageViewModel()
        {
            _itemSource = new ObservableCollection<object>();
            for (int i = 0; i < 28; i++)
                _itemSource.Add(new object());
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }

Full source code is on Github

Best Answer

Answers

  • iboconibocon Member ✭✭
    edited September 21

    I want to do vertical scroll in Grid layout and do horizontal scroll in CollectionView.
    Here is sample xaml architecture,

    <ScrollView Orientation="Vertical">
        <Grid>
            <CollectionView Orientation="Horizontal" />
        </Gird>
    </ScrollView>
    

    And Also, I have multiple CollectionView in one Page. Therefore, I need to scroll Page with CollectionView.

    <ContentPage>
        <ScrollView>
            <CollectionView />
            <CollectionView />
            ...
        </ScrollView>
    </ContentPage>
    
Sign In or Register to comment.