gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 18:03:12 25 4
gpt4 key购买 nike

我有一个列的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com