I have a strange issue as in combobox style when i made virutalzation true, i have a checked Combobox to check all the checkboxes in the combobox items.
in ItemsPanel property, i've made some custom styling with VirtualizingStackPanel as below
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<VirtualizingStackPanel IsItemsHost="True"
IsVirtualizing="True"
VirtualizationMode="Recycling" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
But before and after scrolling the view, it differs.
For e.g., here i try to get very first item of the combobox after scrolling down the items panel as
ComboBoxItem cmbItem = ComboBox1.ItemContainerGenerator.ContainerFromItem(ComboBox1.Items[0]) as ComboBoxItem;
But, i get nothing but NULL here.
So is there anyway we can achieve this using virutalization? (I know it's already virtualizing!). Or we should get rid virtualization and think of another solution. We saw that without virutalization property the combobox loads very slow.
Any thoughts?
Thanks in advance! :)
The NULL is directly a result of virtualization. It is the ComboBoxItem instances that are virtualized/recycled. Only the visible items from your collection will have a ComboBoxItem assigned, so if you ask for the ComboBoxItem on any item that is not visible, you will get back a NULL.