Mahapps.metro: ComboBox has Virtualizing disabled

Created on 7 Mar 2014  Â·  8Comments  Â·  Source: MahApps/MahApps.Metro

Virtualizing is not working with __ComboBox__es when loading long list of data.
After loading the data the ComboBox takes very long time to open, because virtualization is disabled.

A solution is to replace the
<ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" />
with VirtualizingStackPanel but then the grouping does not work anymore.

How do I enable Virtualization in ComboBoxes?

Bug

Most helpful comment

@xxMUROxx i used this to enable virtualization (without grouping, because it breaks the virtualization in .net 4, don't know if it works in .net 4.5)

<Style TargetType="{x:Type ComboBox}"
       BasedOn="{StaticResource MetroComboBox}">
  <Setter Property="ScrollViewer.CanContentScroll"
          Value="True" />
  <Setter Property="ItemsPanel">
    <Setter.Value>
      <ItemsPanelTemplate>
        <VirtualizingStackPanel IsItemsHost="True"
                                KeyboardNavigation.DirectionalNavigation="Contained"
                                VirtualizationMode="Recycling" />
      </ItemsPanelTemplate>
    </Setter.Value>
  </Setter>
</Style>

All 8 comments

@xxMUROxx i used this to enable virtualization (without grouping, because it breaks the virtualization in .net 4, don't know if it works in .net 4.5)

<Style TargetType="{x:Type ComboBox}"
       BasedOn="{StaticResource MetroComboBox}">
  <Setter Property="ScrollViewer.CanContentScroll"
          Value="True" />
  <Setter Property="ItemsPanel">
    <Setter.Value>
      <ItemsPanelTemplate>
        <VirtualizingStackPanel IsItemsHost="True"
                                KeyboardNavigation.DirectionalNavigation="Contained"
                                VirtualizationMode="Recycling" />
      </ItemsPanelTemplate>
    </Setter.Value>
  </Setter>
</Style>

Thanks @punker76 , this works.
But do you also have the problem the the virtualization does not work when you have a CollectionViewSource with GroupDescriptions, even though if you set ComboBoxHelper.EnableVirtualizationWithGrouping="True"

@xxMUROxx that's a .net <= 4 problem, in 4.5 it's better http://msdn.microsoft.com/en-us/library/bb613588(v=vs.110).aspx#grouped_virtualization

@xxMUROxx here is the magic for MahApps

        public static void SetEnableVirtualizationWithGrouping(DependencyObject obj, bool value)
        {
            if (obj is ComboBox)
            {
#if NET4_5
                ComboBox comboBox = obj as ComboBox;

                comboBox.SetValue(EnableVirtualizationWithGroupingProperty, value);
                comboBox.SetValue(VirtualizingPanel.IsVirtualizingProperty, value);
                comboBox.SetValue(VirtualizingPanel.IsVirtualizingWhenGroupingProperty, value);
#else
                obj.SetValue(EnableVirtualizationWithGroupingProperty, false);
#endif
            }
        }

Thanks for the XAML style, but it is not really working when using grouping and .NET4.5. Then the first opening of the ComboBox is slow.

@xxMUROxx i'll take a look into later...

I had to add your code, else it was unbareable slow.
It went from 17 seconds to instant open now!

<Style TargetType="{x:Type ComboBox}"
       BasedOn="{StaticResource MetroComboBox}">
  <Setter Property="ScrollViewer.CanContentScroll"
          Value="True" />
  <Setter Property="ItemsPanel">
    <Setter.Value>
      <ItemsPanelTemplate>
        <VirtualizingStackPanel IsItemsHost="True"
                                KeyboardNavigation.DirectionalNavigation="Contained"
                                VirtualizationMode="Recycling" />
      </ItemsPanelTemplate>
    </Setter.Value>
  </Setter>
</Style>

You can use the VirtualisedMetroComboBox style
Am 22.05.2016 6:13 nachm. schrieb "Ben" [email protected]:

I had to add your code, else it was unbareable slow.
It went from 17 seconds to instant open now!

—
You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub
https://github.com/MahApps/MahApps.Metro/issues/1132#issuecomment-220840835

Was this page helpful?
0 / 5 - 0 ratings

Related issues

feinstein picture feinstein  Â·  18Comments

ghost picture ghost  Â·  18Comments

patriksvensson picture patriksvensson  Â·  18Comments

StickNitro picture StickNitro  Â·  11Comments

benjamin275 picture benjamin275  Â·  17Comments