api - 如何使用 Xamarin 在单元格 View 中显示数据

标签 api xaml user-interface xamarin.forms cross-platform

我正在 Xamarin 中构建跨平台应用程序!

我正在从 Web Api 获取数据并且工作正常,问题是数据显示在 ListView 中类似于列,但我想在 Cells View 中显示该数据所以我可以添加类似 left and right swipe 的功能我不知道该怎么做。

我当前的XAML UI :

    <?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="LastTry.Attendance">


    <ListView x:Name="selectOrd" RowHeight="50" SeparatorColor="White" 
                  HasUnevenRows="True">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell >
                    <StackLayout   Orientation="Horizontal"  >
                        <StackLayout Orientation="Horizontal" VerticalOptions="Center">
                            <Label  Text="{Binding id}" Font="9" TextColor="Black" />
                        </StackLayout>
                        <StackLayout HorizontalOptions="FillAndExpand"  x:Name="employee_name" VerticalOptions="Center"  >
                            <Label  Text="{Binding employee_name}" Font="9" TextColor="Black"   FontAttributes="Bold" HorizontalTextAlignment="Center"/>
                        </StackLayout>
                        <StackLayout HorizontalOptions="FillAndExpand"  x:Name="employee_salary" VerticalOptions="Center"  >
                            <Label  Text="{Binding employee_salary}" Font="9" TextColor="Black"   FontAttributes="Bold" HorizontalTextAlignment="Center"/>
                        </StackLayout>
                        <StackLayout HorizontalOptions="FillAndExpand"  x:Name="employee_age" VerticalOptions="Center"  >
                            <Label  Text="{Binding employee_age}" Font="9" TextColor="Black"   FontAttributes="Bold" HorizontalTextAlignment="Center"/>
                        </StackLayout>
                        <StackLayout HorizontalOptions="FillAndExpand"  x:Name="profile_image" VerticalOptions="Center"  >
                            <Label  Text="{Binding profile_image}" Font="9" TextColor="Black"   FontAttributes="Bold" HorizontalTextAlignment="Center"/>
                        </StackLayout>
                    </StackLayout>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

</ContentPage>

这是我想要的示例:

enter image description here

最佳答案

这是与上面相同的 ListView 的代码:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="MSPL.Views.HomePage">

<AbsoluteLayout>

    <ListView x:Name="Demolist" BackgroundColor="White" ItemSelected="Demolist_ItemSelected">

        <ListView.ItemTemplate>
            <DataTemplate>

                <ImageCell Height="30"
                            Text="{Binding employee_name }"
                       Detail="{Binding employee_age}"
                        ImageSource="falto.png">

                    <ImageCell.ContextActions>
                        <MenuItem x:Name="OnMore" Clicked="OnMore_Clicked" CommandParameter="{Binding .}"  Text="More" />
                        <MenuItem x:Name="OnDelete" Clicked="OnDelete_Clicked" CommandParameter="{Binding .}" Text="Delete" IsDestructive="True" />
                    </ImageCell.ContextActions>
                </ImageCell>

            </DataTemplate>
        </ListView.ItemTemplate>

    </ListView>

    <ImageButton Source="images.png" 
        BackgroundColor="Transparent"
        AbsoluteLayout.LayoutFlags="PositionProportional"  
        AbsoluteLayout.LayoutBounds=".95,.95,55,55"   
        Clicked="ImageButton_Clicked"
    />
</AbsoluteLayout>

关于api - 如何使用 Xamarin 在单元格 View 中显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54460499/

相关文章:

c# - WPF DataGrid 在编辑后更新单元格样式

.net - WPF 数据绑定(bind) - 从父级获取值

c# - 是否有使用新的异步/等待功能编写 .NET API 的指南

c++ - Windows Procedure If Else 语句不适用于消息

c# - 如何更改通用 Windows 平台应用程序中单击事件按钮的背景颜色?

c++ - 在同一个 UI 中使用 QVTKWidget 和 QOpenGLWidget?

java - 如何区分java计算器中的第一个int和第二个int?

user-interface - “准备安装”对话框中的自定义消息包装

objective-c - Swift(或 objective-c)相当于 curl 请求

php - 为什么我的 API REST 的 GET 函数没有返回任何值?