dataSource:SortDescriptor backed by binding property

I am just evaluating the SfListView - very promising. Now ran into a little problem when I try to sort my list dynamically.
I took the BookInfoRepository from the getting started sample. Now I want the sort order to be read from a view models property SortColumn

    public class BookInfoRepository : INotifyPropertyChanged
    {
        public string SortColumn { get; set; } = "BookName";
        // ...

And
    <dataSource:SortDescriptor PropertyName="{Binding SortColumn}" Direction="Ascending" />

I get the error : "No property, bindable property, or event found for 'PropertyName', or mismatching type between value and property."
I tried to use PropertyName="{Binding Path=SortColumn, Source={x:Reference ContentPage}}"
But no luck.

So what am I doing wrong?
Thanks

4 Replies

KA Kayy May 4, 2018 01:44 PM UTC

I managed to get it working in code by recreating the ObservableCollection with the desired sort order when the button command is fired.
Anyway it would be awesome to have this working with the SortDecriptor (and almost no code).


MK Muthu Kumaran Gnanavinayagam Syncfusion Team May 5, 2018 02:12 PM UTC

Hi Kay, 
 
We would like to like to let you know that the PropertyName acquires the name of the property instead of binding its values. So you need to specify the PropertyName directly in string format to resolve the reported error. Please refer the below code example. 
 
Code Example[XAML]: 
<syncfusion:SfListView x:Name="listView"> 
  <syncfusion:SfListView.DataSource> 
    <data:DataSource> 
      <data:DataSource.SortDescriptors> 
        <data:SortDescriptor PropertyName="SortColumn" Direction="Ascending"/> 
      </data:DataSource.SortDescriptors> 
    </dataSource:DataSource> 
  </syncfusion:SfListView.DataSource> 
</syncfusion:SfListView> 
 
Regards, 
G.Muthu kumaran. 



KA Kayy May 7, 2018 08:44 AM UTC

Hi Muthu,

Thank you for confirming this.
So to recap for future readers:
  • Use SortDescriptor for lists whose sort colum is known at compile time and cannot change at runtime
  • Order your list manually in code if you need to change sorting at runtime
  • Never mix both as the SortDescriptor prevents from resorting in code (items will allways be desciptor's sort order)


MK Muthu Kumaran Gnanavinayagam Syncfusion Team May 8, 2018 04:45 AM UTC

Hi Kay, 
 
Thanks for your valuable response. 
 
Regards, 
G.Muthu kumaran. 


Loader.
Up arrow icon