【问题标题】:Xamarin listview of List<List>List<List> 的 Xamarin 列表视图
【发布时间】:2021-02-10 14:48:36
【问题描述】:

我正在制作一个移动应用程序,我正在尝试在列表视图中加载一个列表。该列表有多个元素和一个列表:

public static List<Proposition> PropositionList = new List<Proposition>
{
    new Proposition{
        PropositionId = Guid.Parse("00000000-0000-0000-0000-000000000001"),
        Place= "Barge",
        Date= new DateTime(2020, 7, 11),
        Users= new List<User>(){
            new User
            {
                UserId = Guid.Parse("00000000-0000-0000-0000-000000000001"),
                Name= "Jan Aerts",
                Sterren = 3
            },
            new User
            {
                UserId = Guid.Parse("00000000-0000-0000-0000-000000000002"),
                Naam = "Bart Denys",
                Sterren = 5
            }
        }
    }
}

如何使用 x:Name="StacklayoutMap" 从我的 stacklayout 中的 Users.Name 制作一个列表

<ListView x:Name="lvPropositions" HasUnevenRows="True">
    <ListView.ItemTemplate>
        <DataTemplate>
             <ViewCell>
                 <Frame BorderColor="Black" Margin="10, 0, 10, 0" CornerRadius="45">
                     <StackLayout StyleClass="listitem" Padding="5">
                         <StackLayout Orientation="Horizontal">
                              <Label Style="{DynamicResource DivesLabelStyle}" Text="{Binding Datum}" VerticalOptions="Center" HorizontalOptions="StartAndExpand" />
                              <Label Style="{DynamicResource DivesLabelStyle}" Text="{Binding Plaats}" VerticalOptions="Center" HorizontalOptions="EndAndExpand" />
                         </StackLayout>
                         <StackLayout Orientation="Horizontal">
                             <StackLayout x:Name="StackLayoutMap">
                                
                              </StackLayout>
                              <ImageButton Source="addBlack.png" BackgroundColor="Transparent" HorizontalOptions="EndAndExpand" VerticalOptions="Center" Clicked="BtnRegister_Clicked"/>
                          </StackLayout>
                     </StackLayout>
                </Frame>
         </ViewCell>
     </DataTemplate>
</ListView.ItemTemplate>

【问题讨论】:

    标签: c# listview xamarin xamarin.forms


    【解决方案1】:

    您可以使用可绑定布局

    在 Xaml 中

     <StackLayout Orientation="Horizontal">
         <StackLayout x:Name="StackLayoutMap" BindableLayout.ItemsSource="{Binding Users}">
                <BindableLayout.ItemTemplate>
                    <DataTemplate>
    
                        <Label Text="{Binding Naam}" TextColor="Red" ... />
    
                    </DataTemplate>
                </BindableLayout.ItemTemplate>                     
         </StackLayout>
    //...
    </StackLayout>
    

    有关可绑定布局的更多详细信息,您可以参考此doc

    【讨论】:

    • 快乐编码:)
    猜你喜欢
    • 1970-01-01
    • 2011-05-04
    • 1970-01-01
    • 1970-01-01
    • 2012-09-18
    • 2015-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多