I have a ListBox
that I populate dynamically via a binding (this is defined in a DataTemplate
, which is why the binding is somewhat unusual):
I think the behavior you're seeing is to due to VirtualizingStackPanel.IsVirtualizing
which is True
by default when binding to ItemsSource
of ListBox
if you for eg set your ListBox
such as:
<ListBox VirtualizingStackPanel.IsVirtualizing="False" SelectionMode="Extended" ItemsSource="{Binding DataContext.ResultList, RelativeSource={RelativeSource AncestorType=Window}}">
or
<ListBox ...>
...
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
then you should see all your bound items have their IsSelected
updated accordingly with Ctrl+A or Shift + ...
Properties such as Count
of the collection even with virtualization would report the correct value to accommodate for things like computing the required ScrollBar.Height
. Items which are outside the View-port do not get rendered hence no bindings are in effect on them until they actually get used.