Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Proper way to handle grid headers in a listview?

$
0
0

Hi everyone. I have a listview that uses a grid to defined my columns and rows, like below. I am wondering how to add a header row. Do I need to create a completely new Grid object inside <ListView.HeaderTemplate> that duplicates the same column definitions, etc? It doesn't seem like the most efficient way to add a header (because I would be duplicating the column definitions) so I'm curious if there is a better way? Thanks!!!

    <ListView>
      <ListView.HeaderTemplate>
        <<<<<<< ADD ANOTHER GRID HERE?? >>>>>>>
      </ListView.HeaderTemplate>
      <ListView.ItemTemplate>
        <DataTemplate>
          <ViewCell StyleId="disclosure">
            <ViewCell.View>
              <Grid Padding="0" RowSpacing="2" IsClippedToBounds="True">
                <Grid.ColumnDefinitions Padding="0">
                  <ColumnDefinition Width="20"/>
                  <ColumnDefinition Width="60"/>
                  <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <StackLayout Grid.Column="0" Grid.Row="0" Spacing="0" Padding="0">
                  <Image Source="icon_checked_small.png"></Image>
                </StackLayout>
                <StackLayout Grid.Column="1" Grid.Row="0" Spacing="0" Padding="0">
                  <Label Text="{Binding CustomerNumber}" TextColor="Black" FontSize="14"></Label>
                </StackLayout>
                <StackLayout Grid.Column="2" Grid.Row="0" Spacing="0" Padding="0">
                  <Label Text="{Binding Name}" TextColor="Black" FontSize="14" LineBreakMode="NoWrap"></Label>
                </StackLayout>
                <StackLayout Grid.Column="1" Grid.Row="1" Grid.ColumnSpan="2" Spacing="0" Padding="0">
                  <Label Text="{Binding Addr1}" TextColor="Gray" FontSize="12"></Label>
                </StackLayout>
                <StackLayout Grid.Column="1" Grid.Row="2" Grid.ColumnSpan="2" Spacing="0" Padding="0">
                  <Label Text="{Binding Addr2}" TextColor="Gray" FontSize="12"></Label>
                </StackLayout>
              </Grid>
            </ViewCell.View>
          </ViewCell>
        </DataTemplate>
      </ListView.ItemTemplate>
    </ListView>

Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>