c# - 如何在 Xamarin.Forms 中创建多列 ListView?

标签 c# xamarin.forms

我有一个列的 ListView ,但我想像中继器一样分成两列。在 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;

        }
    }

关于c# - 如何在 Xamarin.Forms 中创建多列 ListView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43633545/

相关文章:

c# - 单声道/单声道开发 : Get solution version at runtime

xamarin.forms - 如何确定xamarin表单中的当前滚动偏移量

c# - 如何在 xamarin 表单 webview 中加载本地 html 文件

azure - 带有 Azure 通知中心的 Xamarin Forms IOS

c# - 在有向图中查找由某些属性隔离的子图

c# - 更改 RazorViewEngine 以在特定项目 (.Net Core) 中查找 View

c# - 为什么 Ruby 套接字服务器可以与其他 Ruby 套接字客户端配合使用,但不能与 C# 套接字客户端配合使用?

c# - Xamarin Forms - 如何获取设备的当前国家/地区

c# - 扩展 Label 控件 - 添加 Click 事件处理程序

c# - LINQ-to-SQL 查询何时执行?