Why is live sorting not invoked?

RogerSchlueter-7899 1,781 Reputation points
2026-05-26T14:50:23.2366667+00:00

Here is the code that implements live sorting of an ObservableCollection(Of Standard) that is displayed in a ListBox:

<CollectionViewSource
	x:Key="cvsStandards"
	IsLiveSortingRequested="True">
	<CollectionViewSource.SortDescriptions>
		<scm:SortDescription PropertyName="Entry" />
	</CollectionViewSource.SortDescriptions>
	<CollectionViewSource.LiveSortingProperties>
		<sys:String>Entry</sys:String>
	</CollectionViewSource.LiveSortingProperties>
</CollectionViewSource>

and

Public Class Standard
	Implements INotifyPropertyChanged

	Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged

Private _Entry As String
Public Property Entry As String
	Get
		Return _Entry
	End Get
	Set(value As String)
		If value <> _Entry Then
			_Entry = value
			OnPropertyChanged("Entry")
		End If
	End Set
End Property


Private Sub OnPropertyChanged(Name As String)
	RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(Name))
End Sub

yet when I either add or edit a value of Entry in the List Box, no sorting takes place. Why not?

Developer technologies | Windows Presentation Foundation

Answer accepted by question author
Nancy Vo (WICLOUD CORPORATION) 8,155 Reputation points Microsoft External Staff Moderator
2026-05-27T03:58:31.87+00:00

Hello @RogerSchlueter-7899 ,

Thanks for your question.

Since your CollectionViewSource has no Source, the sorter does not know what to sort. Furthermore, if your ListBox binds directly to the raw collection instead of going through the CollectionViewSource, the sorting rules are completely bypassed.

You can refer to my example code:

MainWindow.xaml

<Window x:Class="MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        Title="Test Storyboard" Height="912" Width="1908">

    <Window.Resources>
        <CollectionViewSource
            x:Key="cvsStandards"
            Source="{Binding Standards}"
            IsLiveSortingRequested="True">
            <CollectionViewSource.SortDescriptions>
                <scm:SortDescription PropertyName="Entry" />
            </CollectionViewSource.SortDescriptions>
            <CollectionViewSource.LiveSortingProperties>
                <sys:String>Entry</sys:String>
            </CollectionViewSource.LiveSortingProperties>
        </CollectionViewSource>
    </Window.Resources>

    <ListBox ItemsSource="{Binding Source={StaticResource cvsStandards}}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <TextBox Text="{Binding Entry, UpdateSourceTrigger=PropertyChanged}" />
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

</Window>

In MainWindow.xaml.vb

Imports System.Collections.ObjectModel

Public Class MainWindow

    Public Property Standards As ObservableCollection(Of Standard)

    Public Sub New()
        InitializeComponent()

        Standards = New ObservableCollection(Of Standard)()

        Standards.Add(New Standard() With {.Entry = "Zebra"})
        Standards.Add(New Standard() With {.Entry = "Apple"})
        Standards.Add(New Standard() With {.Entry = "Mango"})
        Standards.Add(New Standard() With {.Entry = "Banana"})
        Standards.Add(New Standard() With {.Entry = "Cherry"})

        DataContext = Me

    End Sub

    Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded

        Dim cvs As CollectionViewSource =
            TryCast(Me.Resources("cvsStandards"), CollectionViewSource)

        If cvs IsNot Nothing Then

            Dim view As ListCollectionView =
                TryCast(cvs.View, ListCollectionView)

            If view IsNot Nothing Then
                view.LiveSortingProperties.Add("Entry")
                view.IsLiveSorting = True
            End If

        End If

    End Sub

End Class

In Standard.vb

Imports System.ComponentModel

Public Class Standard
    Implements INotifyPropertyChanged

    Public Event PropertyChanged As PropertyChangedEventHandler _
        Implements INotifyPropertyChanged.PropertyChanged

    Private _Entry As String
    Public Property Entry As String
        Get
            Return _Entry
        End Get
        Set(value As String)
            If value <> _Entry Then
                _Entry = value
                OnPropertyChanged("Entry")
            End If
        End Set
    End Property

    Private Sub OnPropertyChanged(name As String)
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(name))
    End Sub

End Class

I tested and it automatically re-sorts in real time as you type inside any TextBox.

image (13)

I hope this addresses your question. If this response was helpful, please consider following the guidance to provide feedback.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. AI answer

    2026-05-26T14:50:50.83+00:00

    Live sorting is only performed when the underlying collection view both supports live sorting and has it enabled. Defining LiveSortingProperties and setting IsLiveSortingRequested="True" on CollectionViewSource is not sufficient by itself if the view cannot change or does not actually enable live sorting.

    Key points from the APIs involved:

    1. CollectionViewSource.IsLiveSorting is a read‑only dependency property that indicates whether the view is actually doing live sorting. Its value can be:
      • true – live sorting is enabled,
      • false – live sorting is not enabled,
      • null – the view cannot determine whether live sorting is implemented.
         public bool? IsLiveSorting { get; }
      
    2. CollectionViewSource.CanChangeLiveSorting indicates whether the underlying collection view supports turning live sorting on or off:
         public bool CanChangeLiveSorting { get; }
      
      If this is false, the view will not honor IsLiveSortingRequested.
    3. Live sorting is actually implemented by the underlying CollectionView (for example, ListCollectionView or BindingListCollectionView) via ICollectionViewLiveShaping:
         public bool? IsLiveSorting { get; set; }
         public ObservableCollection<string> LiveSortingProperties { get; }
      
      Live sorting only occurs when:
      • IsLiveSorting is true on the concrete view, and
      • the property name (here, "Entry") is present in LiveSortingProperties, and
      • the view type actually supports live sorting.

    In this scenario, the most common reasons no sorting occurs when Entry changes are:

    • The underlying view does not support live sorting, so CanChangeLiveSorting is false and IsLiveSorting remains false or null.
    • The view does not implement ICollectionViewLiveShaping, so IsLiveSortingRequested on CollectionViewSource has no effect.

    To confirm, check at runtime:

    1. Read ((CollectionViewSource)FindResource("cvsStandards")).CanChangeLiveSorting.
    2. Inspect ((CollectionViewSource)FindResource("cvsStandards")).IsLiveSorting.

    If CanChangeLiveSorting is false or IsLiveSorting is false/null, the view is not performing live sorting, which explains why editing Entry in the ListBox does not re‑order the items.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.