0

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! :)

Mayur Paghdal
  • 275
  • 1
  • 2
  • 12
  • why do you want to access the first (or a specific) ComboBoxItem? maybe we have another approach here. In Virtualizing mode, the item you want to get may be in fact not existing (not visible, not loaded). So you have to handle some callback/event. – King King Nov 14 '14 at 05:53
  • my first combobox item is type of 'Select All' checkbox as when i check it, all the combobox items will be checked. and as you said t o handle some callback/event, i think it'll be extra overhead in the code. – Mayur Paghdal Nov 14 '14 at 05:57
  • If you want to check all the checkboxes, just modify the ***data item***, each CheckBox should correspond to some underlying boolean property of a data item. – King King Nov 14 '14 at 06:00
  • @KingKing seems right solution for me.. actually, it was setup already at the way you suggested but after than we removed it. kinda going to implement it again.. :) – Mayur Paghdal Nov 14 '14 at 10:16

1 Answers1

0

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.

Jeff B
  • 1,856
  • 2
  • 17
  • 28