I have used a renderer for my listview because groupheader used to get stuck on scrolling. After using the rendered the scroll issue got fixed but
- The viewcell text got aligned towards the right on Load.
- As you scroll the aligning issue did not appear.
How to align the viewcell text in the correct way (towards left, how it appears when scrolling)
This is my code in renderer
public class CustomListviewEventDetailsRenderer : ListViewRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
{
base.OnElementChanged(e);
if (this.Control != null && e.NewElement != null)
{
var frame = CoreGraphics.CGRect.Empty;
var tbl = new UITableView(frame, UITableViewStyle.Grouped)
{
Source = this.Control.Source
};
this.SetNativeControl(tbl);
}
}
}
XAML:
<local1:CustomListviewEventDetails x:Name="lstItems" HasUnevenRows="True" SeparatorVisibility="None" BackgroundColor="#EEEEEE" ItemsSource="{Binding lstViewItemSource}" ItemSelected="lstItems_ItemSelected" VerticalOptions="FillAndExpand" HeightRequest="{Binding LtHeight}"
IsGroupingEnabled="True" >
<local1:CustomListviewEventDetails.GroupHeaderTemplate>
<DataTemplate>
<local1:CustomViewCellFS Height="30" >
<StackLayout Padding="20,0,0,0" VerticalOptions="CenterAndExpand" BackgroundColor="Green">
<Label Text="{Binding SectionName}" FontSize="15" FontAttributes="Bold" TextColor="Gray" VerticalOptions="CenterAndExpand" VerticalTextAlignment="Center" />
</StackLayout>
</local1:CustomViewCellFS>
</DataTemplate>
</local1:CustomListviewEventDetails.GroupHeaderTemplate>
<local1:CustomListviewEventDetails.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout Padding="0,0,0,0" Margin="0,0,0,0">
<Grid RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="5"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.1*"></ColumnDefinition>
<ColumnDefinition Width="0.9*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Text="{Binding PackageQuantity}" FontSize="15" TextColor="Black" HorizontalOptions="Start" IsVisible="{Binding PackageNameVisibility}" FontAttributes="Bold" >
</Label>
<Label Grid.Row="0" Grid.Column ="1" Text="{Binding PackageName}" FontSize="15" TextColor="Black" HorizontalOptions="Start" HorizontalTextAlignment="Start" IsVisible="{Binding PackageNameVisibility}" FontAttributes="Bold" ></Label>
<Label Grid.Row="1" Grid.Column="0" Text="{Binding Quantity}" FontSize="15" TextColor="Black" HorizontalOptions="Start" HorizontalTextAlignment="Start" IsVisible="{Binding PackageNameVisibility}" >
</Label>
<Label Grid.Row="1" Grid.Column="1" Text="{Binding Item}" FontSize="15" TextColor="Black" HorizontalOptions="StartAndExpand" HorizontalTextAlignment="Start" IsVisible="{Binding PackageNameVisibility}">
</Label>
<Label Grid.Row="2" Grid.Column="0" Text="{Binding SectionQuantity}" FontSize="15" TextColor="Black" HorizontalOptions="Start" HorizontalTextAlignment="Start" IsVisible="{Binding SectionItemVisibility}" >
</Label>
<Label Grid.Row="2" Grid.Column="1" Text="{Binding SectionItem}" FontSize="15" TextColor="Black" HorizontalOptions="StartAndExpand" HorizontalTextAlignment="Start" IsVisible="{Binding SectionItemVisibility}" >
</Label>
<BoxView x:Name="txt" Grid.Row="3" Grid.ColumnSpan="2" HeightRequest="5" ></BoxView>
</Grid>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</local1:CustomListviewEventDetails.ItemTemplate>
</local1:CustomListviewEventDetails>