4

I have listview of one column, but i wanted to divide into two like a repeater. Is it possible in xamarin.forms ?

0

4 Answers 4

11
    <ContentPage.Content>

        <StackLayout>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="30*" />
                    <ColumnDefinition Width="30*" />
                    <ColumnDefinition Width="30*" />
                </Grid.ColumnDefinitions>
                <Label  Grid.Column="0" Grid.Row="0" Text="ID"/>
                <Label  Grid.Column="1" Grid.Row="0" Text="USERS"/>
                <Label Grid.Column="2" Grid.Row="0" Text="PASSWORD"/>

            </Grid>


        <ListView x:Name="listx">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="30*" />
                                <ColumnDefinition Width="30*" />
                                <ColumnDefinition Width="30*" />
                            </Grid.ColumnDefinitions>

                            <Label  Grid.Column="0" Text="{Binding id}"/>
                            <Label  Grid.Column="1" Text="{Binding usr}"/>
                            <Label Grid.Column="2" Text="{Binding pass}"/>
                        </Grid>



                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>

        </ListView>
        </StackLayout>

    </ContentPage.Content>
</ContentPage>

MODEL

public class UserModel
    {
        [PrimaryKey,AutoIncrement]
        public int id { get; set; }
        public string usr { get; set; }
        public string pass { get; set; }


    }

contentPage.xaml.cs

public partial class UserPage : ContentPage
    {

        ObservableCollection<UserModel> Usr_List = new ObservableCollection<UserModel>();

        public UserPage ()
        {
            InitializeComponent ();
            //test data population
            this.Usr_List.Add(new UserModel { id = 1, usr = "test", pass = "test" });
            this.Usr_List.Add(new UserModel { id = 2, usr = "test1", pass = "test1" });
            this.Usr_List.Add(new UserModel { id = 3, usr = "test2", pass = "test2" });

            listx.ItemsSource = this.Usr_List;

        }
    }
Sign up to request clarification or add additional context in comments.

Comments

5

I think you can create a DataTemplate with a ViewCell. Add a Grid to the ViewCell with Rows=1 and Columns=2

something like this sample

<ListView x:Name="listView">
  <ListView.ItemTemplate>
    <DataTemplate>
      <ViewCell>
        <Grid>
          ...
          <Label Text="{Binding Name}" FontAttributes="Bold" />
          <Label Grid.Column="1" Text="{Binding Age}" />
          <Label Grid.Column="2" Text="{Binding Location}" ... />
        </Grid>
      </ViewCell>
    </DataTemplate>
  </ListView.ItemTemplate>
</ListView>

here you can find the description

1 Comment

I find this solution useful, but still, we have to do some workaround for click listener on each item.
3

It's not a relevant question anymore, but the answer is CollectionView ;)

1 Comment

Great thanks for actual solution without third party components. <GridItemsLayout Span="3" /> helps
2

You should either create your own control for this, or have a look at the FlowListView plugin

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.