我有一列的列表视图,但我想像转发器一样分成两部分。 xamarin.forms中可能吗?

最佳答案

    <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>


模型

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;

        }
    }

08-04 17:15