HandyControl
HandyControl copied to clipboard
CheckComboBox Lose Tags While Scrolling In Larg List
Describe the bug When using Large List With CheckComboBox After Specific Items Count, we start losing some tags, while we scrolling
I think this happens due to the rendering behavior of the visual tree.
To Reproduce Steps to reproduce the behavior:
<hc:CheckComboBox
FontSize="19"
VerticalAlignment="Center"
x:Name="ChBoxList"
/>
in code behind
var ls = new List<string>();
for (int i = 0; i < 1000; i++)
{
ls.Add($"[{i}] Rand ELM");
}
this.ChBoxList.ItemsSource = ls;
Expected behavior Tags should not disappear
Screenshots
I added the order to notice caching/buffer behavior So, if we select item Number 50 And 90 and we Scroll To 120 We Will Lose Item Number 50, but 120 not yet.
Environment (please complete the following information):
- .net: [e.g. 4.7.2]
- IDE Rider 2020.3
- Version 3.0.0
The problem occurs because of this line https://github.com/HandyOrg/HandyControl/blob/e5a94c877aaab8d43f6438ae6962cf2364013ef3/src/Shared/HandyControl_Shared/Controls/Input/CheckComboBox/CheckComboBox.cs#L232
I know that we need to get the template from the current CheckComboBoxItem
to have a unified design,
But the problem with ItemContainerGenerator is caching mechanism: virtualization,
So we have two solutions
- first : good for GPU Performance, But not for CPU Performance,
Also have some issues with prmitive types
and this is to implement thing like
private List<CheckComboBoxItem> _latestPopulatedItems = new List<CheckComboBoxItem>();
///
// _panel.Children.Clear();
foreach (var item in SelectedItems)
{
if (ItemContainerGenerator.ContainerFromItem(item) is CheckComboBoxItem checkComboBoxItem)
{
if (_latestPopulatedItems.Contains(checkComboBoxItem))
{
continue;
}
_latestPopulatedItems.Add(checkComboBoxItem);
var tag = new Tag
{
Style = TagStyle,
Tag = checkComboBoxItem
};
tag.SetBinding(ContentControl.ContentProperty, new Binding(DisplayMemberPath) { Source = item });
_panel.Children.Add(tag);
}
}
// then here iterate over _latestPopulatedItems to remove items that do not exist in SelectedItems
// but this will introduce an issue when comparing primitive types, except we used references or unsafe code,
// and we can not force developers to use that
- Second: Bad For GPU
If items collection is very large
, Good For CPU, One Line Implementation. just stop virtualizationVirtualizingPanel.IsVirtualizing="False"
<hc:CheckComboBox
FontSize="19"
VerticalAlignment="Center"
x:Name="ChBoxList"
VirtualizingPanel.IsVirtualizing="False"
/>
The Second Solution is the best One, But This Should be Documented For Such Scenario
另一个相关的问题,可以用楼上的方法解决。 如果选项位于列表的低端,窗口加载之后,这些选项不会被显示。 只有在滚动到那个位置的时候才会显示出来。 https://user-images.githubusercontent.com/1972649/104321969-4848a680-551f-11eb-86f0-8a7cb75f80d0.mp4
@cuiliang two things first, please use a gif instead of mp4, because most people have concerns about downloading mp4 videos int their devices for protection purpose,
second, I know what you said and described that in this issue, but this is the issue itself 😄 because if you have any binding, you will lose theses values from the binding, so you can not store these values in the database,
anyway, if I think this issue should closed, and we just need to mention the second solution in the documentation.
此问题依然存在
closed in 7519c7e
closed in 7519c7e