In UWP the LoadMoreCommnad get called automatically on the initial data load and ui is not rendering.
<ContentView
xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Tyler.EnerGov.Mobile.UI.CustomFields.Container.ContainerView"
xmlns:container="clr-namespace:Tyler.EnerGov.Mobile.UI.Container"
x:DataType="container:ContainerView">
<ContentView.Resources>
<ResourceDictionary>
<!-- Different Data templates -->
<templates:CustomFieldTemplateSelector
x:Key="CustomFieldTemplateSelector"
......
......
NoDataTemplate="{StaticResource NoDataTemplate}"/>
</ResourceDictionary>
</ContentView.Resources>
<ContentView.Content>
<Grid Margin="4" RowDefinitions="*" Padding="10,0">
<listview:SfListView
x:Name="_contentTarget"
VerticalOptions="Fill"
HorizontalOptions="Fill"
Padding="5,0"
SelectionBackground="Transparent"
AutoFitMode="DynamicHeight"
ItemTemplate="{StaticResource CustomFieldTemplateSelector}"/>
</Grid>
</ContentView.Content>
public partial class CustomFieldsContainerView : ContentView
{
private const int _pageSize = 20;
private int _currentPageIndex = 0;
public CustomFieldsContainerView()
{
InitializeComponent();
_contentTarget.LoadMoreOption = LoadMoreOption.Auto;
_contentTarget.LoadMoreCommand = new Command(ExecuteLoadMoreCommand);
}
private void LoadItems()
{
var itemsToLoad = _containerTargetItems?
.Skip((_currentPageIndex - 1) * _pageSize)
.Take(_pageSize);
if (_contentTarget.ItemsSource is ObservableCollection<View> existingItems)
{
foreach (var item in itemsToLoad)
{
existingItems.Add(item);
}
}
else
{
_contentTarget.ItemsSource = new ObservableCollection<View>(itemsToLoad);
}
_currentPageIndex++;
}
private async void ExecuteLoadMoreCommand()
{
// Check if there are more items to load
if (((_currentPageIndex - 1) * _pageSize) < _containerTargetItems.Count)
{
_contentTarget.IsLazyLoading = true;
await Task.Delay(2000);
LoadItems();
}
}
}
Now here I have 30 records in _containerTargetItems.
So, initially it should display 20 items only and when I scroll the list it should call ExecuteLoadMoreCommand and load remaining 10 records.
This works fine as needed in Android & iOS but in the Windows UWP app the ExecuteLoadMoreCommand() gets called automatically when initial data loading gets done and after completing the call its not rendering the UI on the device, showing blank page.
How to fix this issue?
Hi Divyesh Bhatt,
We have checked the reported issue in Windows. We suspect that the ListView may have non-scrollable items in Windows. When LoadMoreOption is set to Auto and the ListView has non-scrollable items, the LoadMoreCommand will continuously trigger until the ListView has scrollable items.
If you don't want the LoadMoreCommand to trigger automatically, you can set LoadMoreOption to AutoOnScroll.
Also, please ensure that IsLazyLoading is set to false after loading the items.
|
private async void ExecuteLoadMoreCommand() { // Check if there are more items to load if (((_currentPageIndex - 1) * _pageSize) < _containerTargetItems.Count) { _contentTarget.IsLazyLoading = true; await Task.Delay(2000);
LoadItems(); _contentTarget.IsLazyLoading = fasle; } }
|
Please let us know if you have any other queries.
Regards,
Jayashree
We suspect that the ListView may have non-scrollable items in Windows.
This is not true, I have scrollable content inside the list view. It does works in Android and iOS, its just having issue with Windows.
Apart from this, now I have used the AutoOnScroll as well, still its not working in Windows. Please check the attached screen recording.
Attachment: recordings_43cdfb47.zip
Hi Divyesh Bhatt,
We have checked the attached videos and it seems like you are using an inner ListView or Expander inside the ListView. To update the ListView height dynamically, you need to set AutoFitMode to "DynamicHeight".
Could you please confirm that you have set AutoFitMode to "DynamicHeight" for all ListViews?
If you still facing any issue please share the issue reproducing sample or code snippet of listview ItemTemplate. This will help us to find a solution as soon as possible.
Regards,
Jayashree
- 3 Replies
- 2 Participants
-
DB Divyesh Bhatt
- Jul 19, 2024 05:36 PM UTC
- Jul 24, 2024 01:09 PM UTC