Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ComboBox has Virtualizing disabled #1132

Closed
michaelmairegger opened this issue Mar 7, 2014 · 8 comments
Closed

ComboBox has Virtualizing disabled #1132

michaelmairegger opened this issue Mar 7, 2014 · 8 comments
Assignees
Labels
Milestone

Comments

@michaelmairegger
Copy link
Contributor

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?

@punker76
Copy link
Member

punker76 commented Mar 7, 2014

@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>

@michaelmairegger
Copy link
Contributor Author

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"

@punker76
Copy link
Member

punker76 commented Mar 7, 2014

@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

@punker76
Copy link
Member

punker76 commented Mar 7, 2014

@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
            }
        }

@michaelmairegger
Copy link
Contributor Author

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.

@punker76
Copy link
Member

punker76 commented Mar 8, 2014

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

@punker76 punker76 added this to the v0.14 milestone Mar 24, 2014
@punker76 punker76 self-assigned this Mar 24, 2014
@punker76 punker76 mentioned this issue Jun 4, 2014
33 tasks
@Hypenate
Copy link

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>

@punker76
Copy link
Member

You can use the VirtualisedMetroComboBox style
Am 22.05.2016 6:13 nachm. schrieb "Ben" notifications@github.com:

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}"> </Style>


You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub
#1132 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants