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.

Scrollview is not working when applied for listview with itemselected function

DemoCloudDemoCloud Member ✭✭✭
edited August 7 in Xamarin.Forms

Hello Sir,
Scrollview is not working when applied for listview with itemselected function.Please help Thanks
Below is the code.

 <ScrollView Orientation="Both">
    <StackLayout Padding="10">
        <Label Text="User Details!" />
    <Button  Text="Add New User " Clicked="Button_Clicked" />

        <ListView x:Name="Models" Header="" ItemSelected="Models_ItemSelected" >
            <ListView.HeaderTemplate>
                <DataTemplate>
                    <Grid >

                        <Grid.RowDefinitions>
                            <RowDefinition Height="20" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="50" />
                            <ColumnDefinition Width="100" />
                            <ColumnDefinition Width="100" />
                            <ColumnDefinition Width="100" />
                            <ColumnDefinition Width="350" />
                        </Grid.ColumnDefinitions>
                        <Label Grid.Column="0"  Text="Id" TextColor="Blue" />
                        <Label Grid.Column="1"  Text="Role" TextColor="Blue" />
                        <Label Grid.Column="2"  Text="Username"  TextColor="Blue"/>
                        <Label Grid.Column="3" Text="Password" TextColor="Blue" />
                        <Label Grid.Column="4"  Text="Email" TextColor="Blue" />
                </Grid>

            </DataTemplate>
            </ListView.HeaderTemplate>

            <ListView.ItemTemplate>
                <DataTemplate>

                    <ViewCell>
                        <Grid  HorizontalOptions="CenterAndExpand">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="100" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="50" />
                                <ColumnDefinition Width="100" />
                                <ColumnDefinition Width="100" />
                                <ColumnDefinition Width="100" />
                                <ColumnDefinition Width="350" />

                            </Grid.ColumnDefinitions>
                            <Label Grid.Column="0" Text="{Binding userId}" />
                            <Label Grid.Column="1" Text="{Binding rolename}" />
                            <Label Grid.Column="2" Text="{Binding username}" />
                            <Label Grid.Column="3" Text="{Binding password}" />
                            <Label Grid.Column="4" Text="{Binding email}" />
                        </Grid>
                </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>

        </ListView>

    <StackLayout VerticalOptions="CenterAndExpand" Padding="5" IsVisible="false" x:Name="update_user">
        <StackLayout Orientation="Horizontal">
            <Entry Text="" x:Name="userid" IsReadOnly="True" HorizontalOptions="FillAndExpand" Placeholder="Please enter userid" FontSize="Small"/>
            <Entry Text="" x:Name="name" HorizontalOptions="FillAndExpand" Placeholder="Please enter name" FontSize="Small" />
        </StackLayout>
        <StackLayout Orientation="Horizontal">
            <Entry Text="" x:Name="username" IsReadOnly="True" HorizontalOptions="FillAndExpand"  FontSize="Small"/>
            <Entry Text="" x:Name="username_new"  HorizontalOptions="FillAndExpand" Placeholder="Please enter new username" FontSize="Small"/>
        </StackLayout>
        <StackLayout Orientation="Horizontal">
            <Entry Text="" x:Name="password" IsReadOnly="True" HorizontalOptions="FillAndExpand"  FontSize="Small"/>
            <Entry Text="" x:Name="password_new"  HorizontalOptions="FillAndExpand" Placeholder="Please enter new password" FontSize="Small"/>
        </StackLayout>
        <StackLayout Orientation="Horizontal">
            <Entry Text="" x:Name="email" HorizontalOptions="FillAndExpand" Placeholder="Please enter email" FontSize="Small"/>
            <Entry Text="" x:Name="designation" HorizontalOptions="FillAndExpand" Placeholder="Please enter designation" FontSize="Small"/>
        </StackLayout>
        <Button Text="Update" x:Name="update" Clicked="update_Clicked" ></Button>

    </StackLayout>
</StackLayout>
</ScrollView>

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    There will be a conflict between the scroll view and a list view.
    Consider putting the top part into the list view's header and bottom into the footer.
    Change the architecture like:

    <ListView ItemsSource="{Binding Items}">
        <ListView.Header>
            <StackLayout>
                <Label Text="User Details!" />
                <Button  Text="Add New User " Clicked="Button_Clicked" />
            </StackLayout>
        </ListView.Header>
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <!--layout-->
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    
        <ListView.Footer>
            <StackLayout VerticalOptions="CenterAndExpand" Padding="5" IsVisible="true" x:Name="update_user">
                <StackLayout Orientation="Horizontal">
                    <Entry Text="" x:Name="userid" IsReadOnly="True" HorizontalOptions="FillAndExpand" Placeholder="Please enter userid" FontSize="Small"/>
                    <Entry Text="" x:Name="name" HorizontalOptions="FillAndExpand" Placeholder="Please enter name" FontSize="Small" />
                </StackLayout>
                <StackLayout Orientation="Horizontal">
                    <Entry Text="" x:Name="username" IsReadOnly="True" HorizontalOptions="FillAndExpand"  FontSize="Small"/>
                    <Entry Text="" x:Name="username_new"  HorizontalOptions="FillAndExpand" Placeholder="Please enter new username" FontSize="Small"/>
                </StackLayout>
                <StackLayout Orientation="Horizontal">
                    <Entry Text="" x:Name="password" IsReadOnly="True" HorizontalOptions="FillAndExpand"  FontSize="Small"/>
                    <Entry Text="" x:Name="password_new"  HorizontalOptions="FillAndExpand" Placeholder="Please enter new password" FontSize="Small"/>
                </StackLayout>
                <StackLayout Orientation="Horizontal">
                    <Entry Text="" x:Name="email" HorizontalOptions="FillAndExpand" Placeholder="Please enter email" FontSize="Small"/>
                    <Entry Text="" x:Name="designation" HorizontalOptions="FillAndExpand" Placeholder="Please enter designation" FontSize="Small"/>
                </StackLayout>
                <Button Text="Update" x:Name="update" Clicked="update_Clicked" ></Button>
    
            </StackLayout>
        </ListView.Footer>
    </ListView>
    
  • DemoCloudDemoCloud Member ✭✭✭

    @LandLu , the lower part of the code is to be displayed on itemselected, i want the scrollview only for the listview.please help
    thanks

  • LandLuLandLu Member, Xamarin Team Xamurai

    Listview has its own scrollview.
    If you only want the listview to be scrolled.
    Try to remove the parent scroll view outside the layout.

  • DemoCloudDemoCloud Member ✭✭✭

    @LandLu , Sir I have already tried that but listview is not getting scroll. How to use listview's scroll. please help .thanks

  • LandLuLandLu Member, Xamarin Team Xamurai
    edited August 7

    When your list view has a set of items and the screen doesn't have enough space to display them, it could be scrolled to show more items.
    But it can't be scrolled on Android if the screen could display all the items in the list view.
    Try to put more items in the items source of the list view.
    You could test the sample here:
    https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/listview/

  • DemoCloudDemoCloud Member ✭✭✭

    @LandLu , Sir I have already tried that but listview is not getting scroll. How to use listview's scroll. please help .thanks

  • LandLuLandLu Member, Xamarin Team Xamurai

    Have you tried the sample from the link I posted?

Sign In or Register to comment.