Hello and hope everyone doing well, i need to calculate each listview's row height. My listivew has uneven rows.
Or if it is possible to get all rows height by once. Thank you
Hello and hope everyone doing well, i need to calculate each listview's row height. My listivew has uneven rows.
Or if it is possible to get all rows height by once. Thank you
if it is possible to get all rows height by once.
I am afraid this answer is no. If rows do not appear in the screen, row cannot be rendered, so rows' height we cannot get it. I create a demo, I get the View height in the <ViewCell Appearing="ViewCell_Appearing" >, But I find I cannot get height when Row appear at the first time, but I can get height at the second time.
Thank you LeonLu. I tried view cell appearing but i am getting always height = -1.
Here is My code:
<StackLayout>
<Button Clicked="Button_Clicked"/>
<ListView x:Name="test" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell Appearing="ViewCell_Appearing">
<StackLayout >
<Label Text="{Binding Name}"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
public class Customer
{
public string Name { get; set; }
}
private void Button_Clicked(object sender, EventArgs e)
{
var items = new ObservableCollection<Customer>();
items.Add(new Customer { Name = "Dimitris" });
test.ItemsSource = items;
}
private async void ViewCell_Appearing(object sender, EventArgs e)
{
var ss = sender as ViewCell;
await DisplayAlert("", ss.Height.ToString(), "OK");
}
Or if it is possible to get each row height after appears in screen.
Example
foreach (var row in listView)
{
}
I set CachingStrategy="RecycleElement", then here is my onAppearing code. Please notice, when your row appear at the first time, the height value is -1, You can get the height value at the second appearing time,
private void ViewCell_Appearing(object sender, EventArgs e)
{
var cell = sender as ViewCell;
var myView=cell.View;
var getHeight= myView.Height;
Console.WriteLine("======"+ getHeight + "===========");
}
8 people are following this question.