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?
@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!BasedOn="{StaticResource MetroComboBox}">
Value="True" />
KeyboardNavigation.DirectionalNavigation="Contained"
VirtualizationMode="Recycling" />
—
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
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)