PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, September 13, 2022

[FIXED] How to display data in Cells View using Xamarin

 September 13, 2022     api, cross-platform, user-interface, xamarin.forms, xaml     No comments   

Issue

I'm building a CrossPlatform App in Xamarin!

I'm getting data from Web Api and it's working fine, the problem is that the data is showing in ListView like columns but I wanted to display that data in Cells View so I can add functionalities like left and right swipeand I don't know how to do this.

My current 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>

Here is an example how I want it:

enter image description here


Solution

Here is the code for the listview same as above:

<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>



Answered By - Hashir Malik
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing