首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用Xamarin在单元格视图中显示数据

如何使用Xamarin在单元格视图中显示数据
EN

Stack Overflow用户
提问于 2019-01-31 20:21:47
回答 1查看 108关注 0票数 2

我正在用Xamarin构建一个CrossPlatform应用程序!

我正在从Web获取数据,它工作得很好,问题是数据像列一样显示在ListView中,但我想在Cells View中显示这些数据,这样我就可以添加像left and right swipe这样的功能,但我不知道如何做到这一点。

我当前的XAML UI

代码语言:javascript
复制
    <?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>

下面是我想要的一个例子:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-04 21:09:42

下面是列表视图的代码,与上面相同:

代码语言:javascript
复制
<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>

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54460499

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档