xamarin forms - ios - listview header appearing below where it should... showing whitespace?

DellBoy 1 Reputation point
2022-01-18T22:04:31.467+00:00

Hope everyone is well. I'm running into a UI problem with my cross platform app for xamarin.forms. Basically it shows different on ios when compared to android.

I have a function on the AdminPage that when button clicks opens the PopupView, the popUp will either contain details on the user, or the order, for this example we are using orderDetails

  private void ShowUserDetails_Clicked(object Sender, EventArgs e)  
    {  
        Button button = (Button)Sender;  
        string UserId = button.CommandParameter.ToString();  
  
        PopupNavigation.Instance.PushAsync(new PopupView(-1, int.Parse(UserId)));  
    }  

The problem lies in the UI of the popUp, if you notice the android phone on the left of the image below. It loads the way I want it to. Displaying lable for email | phone number, followed by listview of OrderDetails below. As you can see it looks fine on the android. The problem is on the ios. Where is the whitespace coming from at the top of the PopUpView?

If you take a close look at the PopUpView on the iphone 11, there is a scroll bar to the right of the popUp . It starts where the text starts, and I cant scroll any further up. Its almost as if there is an extra row placed before anything else. I have looked extensively through the code and can't figure it out. So I want to remove the whitespace, have even tried listview.scrollTo for the listview but with no success..any help would be great thank you

166145-box.png

<?xml version="1.0" encoding="utf-8" ?>  
<pages:PopupPage xmlns="http://xamarin.com/schemas/2014/forms"  
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"  
             x:Class="BottleShop.Views.PopupView"  
    xmlns:pages="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup"  
             xmlns:converters="clr-namespace:BottleShop.ViewModels.Converters">  
  
    <StackLayout x:Name="StackSearchResultsOuter" BackgroundColor="Transparent" HorizontalOptions="Center" VerticalOptions="Center">     
            <StackLayout.Resources>  
                <converters:ProductIdToProductNameConverter x:Key="converter"/>  
            </StackLayout.Resources>  
  
  
            <BoxView x:Name="InvisibleSpacer" BackgroundColor = "Transparent"  
        HeightRequest="80" />  
  
            <StackLayout x:Name="StackLayoutOrders" IsVisible="{Binding SLOrders}">  
                <ListView BackgroundColor="White" ItemsSource="{Binding PreviousOrderDetailsForUserLV}" HasUnevenRows="True" SeparatorVisibility="None">  
  
                    <ListView.Header>  
                        <Grid>  
  
                            <Grid.RowDefinitions>  
                            <RowDefinition Height="Auto"/>  
                            <RowDefinition Height="*"/>  
                        </Grid.RowDefinitions>  
  
                            <Grid.ColumnDefinitions>  
                                <ColumnDefinition Width="30*" />  
                                <ColumnDefinition Width="25*" />  
                                <ColumnDefinition Width="25*" />  
                                <ColumnDefinition Width="20*" />  
                            </Grid.ColumnDefinitions>  
  
  
                        <Label Grid.Column="0" Grid.ColumnSpan="4" Grid.Row="0" x:Name="UserInfoLabel" HorizontalOptions="Center" Margin="10,10,0,0"/>  
  
                       <BoxView Grid.Row="1"  
                             Grid.ColumnSpan="4"   
                             BackgroundColor="LightGray"/>  
  
                        <Label Grid.Column="0" Text="Product" Grid.Row="1" HorizontalOptions="Center" Margin="0,10,0,0"/>  
                            <Label Grid.Column="1" Grid.Row="1" Text="Quantity" HorizontalOptions="Center" Margin="0,10,0,0"/>  
                            <Label Grid.Column="2" Grid.Row="1" Text="Price" HorizontalOptions="Center" Margin="0,10,0,0"/>  
                            <Label Grid.Column="3" Grid.Row="1" Text="Sub" HorizontalOptions="Center" Margin="0,10,0,0"/>  
                            <!--<BoxView Grid.Row="1"  
                             Grid.ColumnSpan="4"  
                             HeightRequest="1"  
                             BackgroundColor="LightGray"/> -->  
  
  
                        </Grid>  
                    </ListView.Header>  
  
                    <ListView.ItemTemplate>  
                        <DataTemplate>  
                            <ViewCell>  
                                <Grid Padding="10" RowSpacing="10" ColumnSpacing="10">  
                                    <Grid.RowDefinitions>  
                                        <RowDefinition Height="Auto"/>  
                                        <RowDefinition Height="*"/>  
                                    </Grid.RowDefinitions>  
                                    <Grid.ColumnDefinitions>  
  
                                        <ColumnDefinition Width="43*" />  
                                        <ColumnDefinition Width="8*" />  
                                        <ColumnDefinition Width="25*" />  
                                        <ColumnDefinition Width="24*" />  
  
                                    </Grid.ColumnDefinitions>  
                                    <Label Grid.Column="0" Grid.Row="0" HorizontalOptions="StartAndExpand" VerticalOptions="StartAndExpand" Text="{Binding ProductId, Converter={StaticResource converter}}"/>  
                                    <Label Grid.Column="1" Grid.Row="0" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" Text="{Binding Quantity}"/>  
                                    <Label Grid.Column="2" Grid.Row="0" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" Text="{Binding PriceOfItem, StringFormat='£{0:0.00}'}"/>  
                                    <Label Grid.Column="3" Grid.Row="0" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" Text="{Binding SubtotalForThisItem, StringFormat='£{0:0.00}'}"/>  
                                </Grid>  
                            </ViewCell>  
                        </DataTemplate>  
                    </ListView.ItemTemplate>  
                </ListView>  
            </StackLayout>  
  
            <StackLayout x:Name="StackLayoutUsers" IsVisible="{Binding SLUsers}">  
                <ListView x:Name="UsersListView" BackgroundColor="White" ItemsSource="{Binding AllExistingUsersLV}" HasUnevenRows="True" SeparatorVisibility="None">  
                    <ListView.Header>  
                        <Grid>  
  
                            <Grid.RowDefinitions>  
                                <RowDefinition Height="*"/>  
                                <RowDefinition Height="Auto"/>  
                            </Grid.RowDefinitions>  
  
                            <Grid.ColumnDefinitions>  
                                <ColumnDefinition Width="30*" />  
                                <ColumnDefinition Width="25*" />  
                                <ColumnDefinition Width="25*" />  
                                <ColumnDefinition Width="20*" />  
                            </Grid.ColumnDefinitions>  
  
                            <Label Grid.Column="0" Text="Address Line 1" Grid.Row="0" HorizontalOptions="Center" Margin="0,10,0,0"/>  
                        <Label Grid.Column="1" Grid.Row="0" Text="Line 2" HorizontalOptions="Center" Margin="0,10,0,0"/>  
                            <Label Grid.Column="2" Grid.Row="0" Text="Town" HorizontalOptions="Center" Margin="0,10,0,0"/>  
                            <Label Grid.Column="3" Grid.Row="0" Text="Mobile" HorizontalOptions="Center" Margin="0,10,0,0"/>  
                            <BoxView Grid.Row="1"  
                             Grid.ColumnSpan="4"  
                             HeightRequest="1"  
                             BackgroundColor="LightGray"/>  
  
  
                        </Grid>  
                    </ListView.Header>  
  
                    <ListView.ItemTemplate>  
                        <DataTemplate>  
                            <ViewCell>  
                                <Grid Padding="10" RowSpacing="10" ColumnSpacing="10">  
                                    <Grid.RowDefinitions>  
                                        <RowDefinition Height="Auto"/>  
                                        <RowDefinition Height="*"/>  
                                    </Grid.RowDefinitions>  
                                    <Grid.ColumnDefinitions>  
  
                                        <ColumnDefinition Width="43*" />  
                                        <ColumnDefinition Width="8*" />  
                                        <ColumnDefinition Width="25*" />  
                                        <ColumnDefinition Width="24*" />  
  
                                    </Grid.ColumnDefinitions>  
                                <Label Grid.Column="0" Grid.Row="0" HorizontalOptions="StartAndExpand" VerticalOptions="EndAndExpand" Text="{Binding AddressLine1}"/>  
                                <Label Grid.Column="1" Grid.Row="0" HorizontalOptions="StartAndExpand" VerticalOptions="EndAndExpand" Text="{Binding AddressLine2}"/>  
                                <Label Grid.Column="2" Grid.Row="0" HorizontalOptions="EndAndExpand" VerticalOptions="EndAndExpand" Text="{Binding City}"/>  
                                <Label Grid.Column="3" Grid.Row="0" HorizontalOptions="EndAndExpand" VerticalOptions="EndAndExpand" Text="{Binding MobileNumber}"/>  
                                </Grid>  
                            </ViewCell>  
                        </DataTemplate>  
                    </ListView.ItemTemplate>  
                </ListView>  
            </StackLayout>  
  
  
  
        </StackLayout>  
   <!-- </Grid>   -->  
</pages:PopupPage>  
  
using BottleShop.Data;  
using BottleShop.Models;  
using Microsoft.AppCenter.Crashes;  
using System;  
using System.Collections.Generic;  
using System.Collections.ObjectModel;  
using Xamarin.Forms.Xaml;  
  
namespace BottleShop.Views  
{  
    [XamlCompilation(XamlCompilationOptions.Compile)]  
    public partial class PopupView //: ContentView  
    {  
        public ObservableCollection<OrderDetailsModel> PreviousOrderDetailsForUserLV { get; set; }  
  
        OrdersDatabaseController RecentOrdersController = new OrdersDatabaseController();  
  
        public ObservableCollection<UserModel> AllExistingUsersLV { get; set; }  
        UserDatabaseController UserController = new UserDatabaseController();  
  
        public bool SLOrders { get; set; }  
        public bool SLUsers { get; set; }  
  
    public PopupView(int OrderId, int UserId)  
        {  
            try  
            {  
                InitializeComponent();  
  
  
                //Show Orders PopUp  
                if (OrderId != -1)  
                {  
                    SLOrders = true;  
                    SLUsers = false;  
  
                    List<OrderDetailsModel> RecentOrderDetailsList = RecentOrdersController.GetAllOrderDetailsByOrderId(OrderId);  
                    PreviousOrderDetailsForUserLV = new ObservableCollection<OrderDetailsModel>(RecentOrderDetailsList as List<OrderDetailsModel>);  
  
                    int startingHeightOfSL = 180;  
                    int countOfOrderDetailRecords = PreviousOrderDetailsForUserLV.Count;  
                    var tempHeightofStackSearchResults = countOfOrderDetailRecords * 40;  
  
                    if (countOfOrderDetailRecords > 1)  
                    {  
                        StackSearchResultsOuter.HeightRequest = startingHeightOfSL + tempHeightofStackSearchResults;  
                    }  
                    else  
                    {  
                        StackSearchResultsOuter.HeightRequest = startingHeightOfSL;  
                    }  
                      
                    UserInfoLabel.Text = "Email: " + PreviousOrderDetailsForUserLV[0].UserName + " | " + "Mobile: " + PreviousOrderDetailsForUserLV[0].UserMobileNumber;  
  
                }  
                else //Show Users PopUp  
                {  
                    if(UserId != -1)  
                    {  
                        var a = 1;  
  
                        SLOrders = false;  
                        SLUsers = true;  
  
                        List<UserModel> UsersList = UserController.GetUserWithId(UserId);  
                        if (UsersList != null)  
                        {  
                            AllExistingUsersLV = new ObservableCollection<UserModel>(UsersList as List<UserModel>);  
                        }  
  
                        StackSearchResultsOuter.HeightRequest = 180;  
                    }  
                }  
  
                BindingContext = this;  
  
            }  
            catch (Exception ex)  
            {  
                Crashes.TrackError(ex);  
            }  
        }  
    }  
}  
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,325 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 29,301 Reputation points Microsoft Vendor
    2022-01-19T09:58:52.203+00:00

    Hello,

    Welcome to our Microsoft Q&A platform!

    there is a scroll bar to the right of the popUp . It starts where the text starts, and I cant scroll any further up. Its almost as if there is an extra row placed before anything else.

    You set HasUnevenRows="True", so the listview has uneven rows, but the height of each row is calculated according to the fixed 40.

     var tempHeightofStackSearchResults = countOfOrderDetailRecords * 40;  
    

    Then the listview will not be fully expanded , UITableview(listview) extends UIScrollview, it needs to be scrolled and the scroll bar appears.

    I'm afraid you have to change the height and disable scrolling.

    use CustomRenderer to disable scrolling

    [assembly: ExportRenderer(typeof(ListView), typeof(ListViewRenderer_iOS))]  
    namespace ListViewHeaderViewDemo.iOS  
    {  
        public class ListViewRenderer_iOS: ListViewRenderer  
        {  
            ListView mListView;  
            protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)  
            {  
                base.OnElementChanged(e);  
                if (e.OldElement != null)  
                {  
                    // Unsubscribe  
                }  
      
                if (e.NewElement != null)  
                {  
                    //Control.ContentInsetAdjustmentBehavior= UIScrollViewContentInsetAdjustmentBehavior.Never;  
                    Control.ScrollEnabled = false;  
                }  
            }  
        }  
    }  
    

    Best Regards,
    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments