paul sim
paul sim

Reputation: 453

xamarin how to show multiple column grid which support both andriod and iOS

I want to create a list view with four column, first two column will have text and next two column will have clickable button(image). Number of rows is not fixed- so data binding is require. Should support android and iOS. please suggest which xamarin control will be best suited for me.

Can i use data template as shown in https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/templates/data-templates/selector/

or should use Grid, Grid layout or any other.

======== Solution Applied=============

<ListView x:Name="listViewExpenses" CachingStrategy="RecycleElement" VerticalOptions="FillAndExpand" RowHeight="40">
<ListView.ItemTemplate>
    <DataTemplate>
        <ViewCell>
            <Grid >
                <Grid.ColumnDefinitions>

                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="40"/>
                </Grid.ColumnDefinitions>
                <!--<Label x:Name="idLabel" Text="{Binding Id}"/>-->
                <Label x:Name="textLabel1" Grid.Column="0" Text="{Binding Text}"/>
                <!--<Button x:Name="btnEdit" Image="icon.png" HeightRequest="50" WidthRequest="50"  Grid.Column="2" CommandParameter="{Binding Id}"  Clicked="OnEditClicked" />-->
                <StackLayout Grid.Column="1">
                    <Image Source="EditRed.png" VerticalOptions="Center" >
                        <Image.GestureRecognizers>
                            <TapGestureRecognizer
    Tapped="OnEditTapped" 
        CommandParameter="{Binding Id}"/>
                        </Image.GestureRecognizers>
                    </Image>
                </StackLayout>
            </Grid>
        </ViewCell>
    </DataTemplate>
</ListView.ItemTemplate>
</ListView>`enter code here`

===================================== Thanks,

@paul

Upvotes: 0

Views: 1905

Answers (2)

Yuri S
Yuri S

Reputation: 5370

Data templates you mentioned is required in case of different row views. For your case Grid should be sufficient. You can add rows dynamically for example like shown here

https://forums.xamarin.com/discussion/42393/need-to-add-rows-dynamically-in-a-grid

If that doesn't work you can use ListView with custom cells

https://developer.xamarin.com/guides/xamarin-forms/user-interface/listview/customizing-cell-appearance/

Upvotes: 0

Steve Chadbourne
Steve Chadbourne

Reputation: 6953

As the number of rows is not fixed but each row will look the same, I would suggest a List View with an inline data template.

https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/templates/data-templates/creating/

Upvotes: 1

Related Questions