Dear support Team
Binding the ListView Selected Items throws an Error as soon the selections is changed.
Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
at Syncfusion.ListView.XForms.SelectionController.ProcessMultipleSelection (Syncfusion.ListView.XForms.ListViewItemInfoBase itemInfo, System.Object itemdata) [0x00019] in <a23e73410d084cd6b84613a8e2def977>:0
at Syncfusion.ListView.XForms.SelectionController.ProcessSelection (Syncfusion.ListView.XForms.ListViewItemInfoBase itemInfo, System.Object itemdata) [0x00031] in <a23e73410d084cd6b84613a8e2def977>:0
at Syncfusion.ListView.XForms.SelectionController.HandleTouchInteraction (Syncfusion.ListView.XForms.TouchGesture gesture, Syncfusion.ListView.XForms.ListViewItemInfoBase itemInfo, Xamarin.Forms.Point position) [0x000d8] in <a23e73410d084cd6b84613a8e2def977>:0
at Syncfusion.ListView.XForms.ListViewItemInfoBase.HandleTouchInteraction (Syncfusion.ListView.XForms.TouchGesture gesture, Xamarin.Forms.Point position) [0x0008d] in <a23e73410d084cd6b84613a8e2def977>:0
at Syncfusion.ListView.XForms.Android.ListViewItemRenderer.OnClick (Android.Views.View view) [0x00086] in <7006034e31104b119b70b80fa946db95>:0
at Syncfusion.ListView.XForms.Android.ListViewItemRenderer.OnSingleTapUp (Android.Views.MotionEvent e) [0x00000] in <7006034e31104b119b70b80fa946db95>:0
at Android.Views.GestureDetector+IOnGestureListenerInvoker.n_OnSingleTapUp_Landroid_view_MotionEvent_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_e) [0x00010] in /Users/xtmq/xamarin/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-30/mcw/Android.Views.GestureDetector.cs:697
at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.59(intptr,intptr,intptr)
I did the binding like explained in the documentation. What is the issue here?
"1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:xForms="clr-namespace:Syncfusion.ListView.XForms;assembly=Syncfusion.SfListView.XForms"
x:Class="ClassicXamarin.Mobile.ListViewPage" x:Name="ThisPage">
<ContentPage.BindingContext>
<x:Reference Name="ThisPage">x:Reference>
ContentPage.BindingContext>
<ContentPage.Content>
<StackLayout>
<Label Text="New User"/>
<Entry/>
<Button Text="Add item to list"/>
<Label Text="All Users"
FontSize="Large"/>
<xForms:SfListView ItemsSource="{Binding Users}"
SelectedItems="{Binding SelectedItems}"
SelectionMode="Multiple"/>
<Label Text="Selected Users"
FontSize="Large"/>
<xForms:SfListView ItemsSource="{Binding SelectedItems}"/>
StackLayout>
ContentPage.Content>
ContentPage>
using System.Collections.ObjectModel;
using Xamarin.Forms.Xaml;
namespace ClassicXamarin.Mobile
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ListViewPage
{
ObservableCollection<string> _users;
ObservableCollection<object> _selectedItems;
public ListViewPage()
{
InitializeComponent();
Users = new ObservableCollection<string>
{
"Hans",
"Fritz",
"Manuel"
};
}
public ObservableCollection<string> Users
{
get => _users;
set
{
_users = value;
OnPropertyChanged(nameof(Users));
}
}
public ObservableCollection<object> SelectedItems
{
get => _selectedItems;
set
{
_selectedItems = value;
OnPropertyChanged(nameof(SelectedItems));
}
}
}
}
The whole Project is under:
https://github.com/PatrickRainer/PrismApp
Thank you for your Feedback.
br Patrick
|
public ListViewPage()
{
InitializeComponent();
Users = new ObservableCollection<string>
{
"Hans",
"Fritz",
"Manuel"
};
SelectedItems = new ObservableCollection<object>();
} |
Dear Kakshimi
Sorry my bad in the sample.
Now, can I bind the SelectedItems to a property in my model? So like:
<xForms:SfListView SelectionMode="Multiple"
ItemsSource="{Binding BooksProvider}"
SelectedItems="{Binding Person.Books}"
The model would be like this:
public class Person
{
public string Name { get; set; }
public List<Book> Books { get; set; } = new List<Book>();
}
public class Book
{
public string ISBN { get; set; }
public string Title { get; set; }
public override string ToString()
{
return Title;
}
}
Github Sample: https://github.com/PatrickRainer/SfListViewSample
Br Patrick
|
public class Person
{
public string Name { get; set; }
public ObservableCollection<object> Books { get; set; } = new ObservableCollection<object>();
} |
Ok, thank you that works so far, but is a bit complicated.
Is it possible to use a "ValueConverter" for this case?
br Patrick
Thank you.
That the list does not implement the INotifyCollectionchanged interface is clear.
What I mean is, if use an "ObservableCollection<Book>" and not an "ObservableCollection<object>" in the model. Is it then possible to use a "ValueConverter"?
Br Patrick
Ok, thank you for this explanation.
br Patrick