Currently the LoadOnDemandCollection accepts a callback of the following format in the constructor:
public LoadOnDemandCollection(Func<CancellationToken, IEnumerable> action)
It is a very common scenario to populate the items asynchronously. In its current form the collection would require blocking the current thread to populate the results:
ItemsSource = new ListViewLoadOnDemandCollection((cancelationToken) =>
{
var result = new List<ItemsModel>();
try
{
var items = dataService.GetItemsAsync().Result;
// TODO: Handle the result.
return result;
}
catch (Exception e)
{
// TODO: Handle the exception.
return null;
}
});
This is not desired, as using Task.Result blocks the current thread and is considered an anti-pattern, in general.
A better approach would be to add a second overload of the constructor, allowing asynchronous calls:
public LoadOnDemandCollection(Func<CancellationToken, Task<IEnumerable>> action)
This way we can use async and await in the callback instead:
ItemsSource = new ListViewLoadOnDemandCollection(async (cancelationToken) =>
{
var result = new List<ItemsModel>();
try
{
var items = await dataService.GetItemsAsync();
// TODO: Handle the result.
return result;
}
catch (Exception e)
{
// TODO: Handle the exception.
return null;
}
});
According to my tests, the first blocking approach is not a problem, as the ListViewLoadOnDemandCollection starts a thread internally. That behavior is not obvious however, and using Task.Result is somewhat counterintuitive, so the second approach is much better from the user's perspective.
public class City
{
public string Name { get; set; }
public string Country { get; set; }
public Image CountryFlag { get; set; }
}
Hi Team,
In the current RadListView implementation, the RadListView will start with all the groups expanded. The only way to have any form of preference is to programmatically interact with the Dataview after-the-fact https://docs.telerik.com/devtools/maui/controls/listview/grouping/expand-collapse
This is problematic because I need to take a wild guess as to how long it takes for the data to load in the RadListView.Loaded event and then manually collapse them.
Even if I time this perfectly... this results in visual flash for the user because the ListView starts expanded and immediately collapses.
A better approach that I am requesting a feature for is to have a property available for the RadListView that sets this value ahead of time.
For example, you could add it as a BindableProperty on the GroupDescriptorBase class.
// THE OFFICIAL BASE CLASS
public abstract class GroupDescriptorBase : OrderedDescriptorBase, IKeyLookup
{
public object GetKey(object item) => this.GetKeyCore(item);
protected abstract object GetKeyCore(object item);
protected virtual object GetDefaultKey(object item) => item;
// SUGGESTED IMPROVEMENT
public bool IsExpanded
{
get => (bool)GetValue(IsExpandedProperty);
set => SetValue(IsExpandedProperty, value);
}
public static readonly BindableProperty IsExpandedProperty = BindableProperty.Create(
nameof(IsExpanded),
typeof(bool),
typeof(GroupDescriptorBase),
true, // the default right now is true... do not change that because no breaking changes
propertyChanged: OnIsExpandedChanged);
static void OnIsExpandedChanged(BindableObject bindable, object oldValue, object newValue)
{
if (bindable is GroupDescriptorBase self)
{
if (!(bool)newValue)
{
// PLEASE DO NOT START WITH GROUPS EXPANDED
}
}
}
}
Or you could even put it a little lower, next to the BindableProperty SortOrder:
Thank you for your consideration,
Jian
on the GroupDefinition is to have a IsExap
Hi Team,
Please expose the ScrollViewer, or expose a method on the RadListView that allows the developer to set a Y device-independent vertical position. Setting the Y value will trigger the internal/native scrollview to go to that position without any special animations or manipulation. Just a pure position set.
I need to be able to programmatically scroll to a specific position in the list. Yes, I am aware of the ScrollToItem methods, however that will not work in my case as I explicitly need the Y position (for acceleration and manipulation of the exact position).
As an example, here's how I am currently doing it for a ScrollView:
private async Task AutoScrollAsync()
{
while (!(this.ScrollVelocity == 0 || this.ScrollVelocity > 0 && this.IsScrolledToBottom() || this.ScrollVelocity < 0 && this.IsScrolledToTop()))
{
await this.scrollView.ScrollToAsync(0, this.CalculateNextScrollY(), false);
await Task.Delay(ScrollDelay);
}
this.StopScrolling();
}
I am hoping to be able to do the same thing for the RadListView.
Thank you,
Aaron
When having a nested grid layouts with auto and definitive row heights, the content in the ListView ItemTemplate is not property sized only on iOS. On Android, MacCatalyst and WinUI the content is property sized.
Solution:
1. Using only auto-sized grid rows,
2. Using grouping and simplifying the layout, removing nested grid layouts, and using a vertical stack.
When setting margin to the elements in the template, the margin is not respected
Since migrating to MAUI .NET8 GA 8.0.3 (and Telerik 6.5) - on iOS the RadListView keeps repeatedly triggering the defined LoadOnDemand command to get more items even though list has not been scrolled by user.
the behavior is valid for the command, event and collection and when automatic load on demand mode is used.
When using manual mode, it works as expected.
Having ContentViews for left and right item swipe
The ListView crashes
The bug can be reproduced quite easily with the SDK examples. Choose any ListView example from the LoadOnDemand category that uses LoadOnDemandMode set to Automatic, e.g. ListView/LoadOnDemand/LoadOnDemandEvent. Remove the initial items from the ItemsSource:
public ViewModel()
{
this.Source = new ObservableCollection<string>();
//for (int i = 0; i < 14; i++)
//{
// this.Source.Add(string.Format("Item {0}", i));
//}
this.LoadItemsCommand = new Command(this.LoadItemsCommandExecute);
}
Run the example to observe the exception almost immediately.