Search code examples
xamlwindows-phone-8.1windows-phone

XAML (WP8.1) scrollable ListView and fixed Grid bottom of DataTemplate


<DataTemplate>
    <ScrollViewer>
        <Grid>
            ... same rows and controls 20% of screen
        </Grid>
        <ListView>
        </ListView>
    </ScrollViewer>
</DataTemplate>

With this template there are

  1. fixed Grid first

  2. scrollable ListView second

How create template with

  1. scrollable ListView at top

  2. fixed Grid at bottom

?

P.S. There are online or compiled demo different xaml layout/templates?


Solution

  • Don't put a ListView inside a ScrollViewer because you will lose virtualization if you are using it, which will degrade performance significantly.

    If you want the Grid to always be visible then use the following:

    <DataTemplate>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <ListView Grid.Row="0"/>
            <Grid Grid.Row="1" Height="100"/> <!-- Set any fixed height -->
        </Grid>
    </DataTemplate>
    

    If you want the Grid to scroll with the list use a Footer:

    <DataTemplate>
        <ListView>
            <ListView.Footer>
                <!-- Set any fixed height -->
                <Grid Height="100"/>
            </ListView.Footer>
        </ListView>
    </DataTemplate>