Hello San,
You haven't provided enough information, but it's likely due to you not setting your BindingContext correctly, thus the RadListView's ItemsSource is null. I've written you a demo, attached.
For your convenience, here is the code:
namespace
SelectedItemsOnPageLoad.Portable
{
public
partial
class
StartPage : ContentPage
{
private
ObservableCollection<BaseListClass> _items;
private
ObservableCollection<BaseListClass> selectedInstances =
new
ObservableCollection<BaseListClass>();
public
StartPage()
{
InitializeComponent();
}
private
void
Handle_SelectionChanged(
object
sender, NotifyCollectionChangedEventArgs e)
{
}
protected
override
void
OnAppearing()
{
base
.OnAppearing();
IsBusy =
true
;
LoadData();
IsBusy =
false
;
foreach
(var selectedInstance
in
selectedInstances)
{
var instanceInItemsList = Items.FirstOrDefault(item => item.Name == selectedInstance.Name);
listView.SelectedItems.Add(instanceInItemsList);
}
}
public
ObservableCollection<BaseListClass> Items
{
get
=> _items ?? (_items =
new
ObservableCollection<BaseListClass>());
set
{
_items = value;
OnPropertyChanged();
}
}
void
LoadData()
{
var list = Enumerable.Range(1, 20).Select(i =>
new
BaseListClass
{
Name = $
"Item {i}"
});
foreach
(var item
in
list)
{
Items.Add(item);
}
// adding some of the items to selected items collection
selectedInstances.Add(Items[1]);
selectedInstances.Add(Items[3]);
selectedInstances.Add(Items[4]);
}
}
public
class
BaseListClass
{
public
string
Name {
get
;
set
; }
}
}
Note that I removed the await operator from the call on LoadData. Your shared code is not compilable as LoadData is not marked async. Additionally, you should never use async void unless it's top level event handler.
I've attached a runnable demo for you to see this in action at runtime:
Regards,
Lance | Tech Support Engineer, Sr.
Progress Telerik
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items