- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 ItemsControl
包含我想虚拟化的数据列表,但是 VirtualizingStackPanel.IsVirtualizing="True"
似乎不适用于 ItemsControl
.
真的是这样,还是有另一种我不知道的方法?
为了测试我一直在使用以下代码块:
<ItemsControl ItemsSource="{Binding Path=AccountViews.Tables[0]}"
VirtualizingStackPanel.IsVirtualizing="True">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Initialized="TextBlock_Initialized"
Margin="5,50,5,50" Text="{Binding Path=Name}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
ItemsControl
到
ListBox
,我可以看到
Initialized
事件只运行了几次(巨大的利润只是让我只需要浏览几条记录),但是作为
ItemsControl
每个项目都被初始化。
ItemsControlPanelTemplate
到
VirtualizingStackPanel
但这似乎没有帮助。
最佳答案
实际上,它不仅仅是制作 ItemsPanelTemplate
。使用 VirtualizingStackPanel
.默认 ControlTemplate
对于 ItemsControl
没有 ScrollViewer
,这是虚拟化的关键。添加到 ItemsControl
的默认控制模板(使用 ListBox
的控制模板作为模板)为我们提供了以下信息:
<ItemsControl ItemsSource="{Binding AccountViews.Tables[0]}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Initialized="TextBlock_Initialized"
Text="{Binding Name}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel IsVirtualizing="True"
VirtualizationMode="Recycling" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.Template>
<ControlTemplate TargetType="ItemsControl">
<Border BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{TemplateBinding BorderBrush}"
Background="{TemplateBinding Background}">
<ScrollViewer CanContentScroll="True"
Padding="{TemplateBinding Padding}"
Focusable="False">
<ItemsPresenter />
</ScrollViewer>
</Border>
</ControlTemplate>
</ItemsControl.Template>
</ItemsControl>
(顺便说一句,查看默认控件模板的好工具是
Show Me The Template )
ScrollViewer.CanContentScroll="True"
,见
here为什么。
VirtualizingStackPanel.VirtualizationMode="Recycling"
.这将减少
TextBlock_Initialized
的次数被调用,但是在屏幕上可以看到许多 TextBlock。你可以阅读更多关于 UI 虚拟化
here .
ItemsControl
与
ListBox
:)
ItemsControl
不在“实现性能特征的控件”表中,这就是我们需要编辑控件模板的原因。
关于wpf - 虚拟化 ItemsControl?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2783845/
我正在使用 M-V-VM 并在我的 ViewModel 上有一个名为“EntitySelectedCommand”的命令。 我试图让 ItemsControl 中的所有项目来触发这个命令,但是它不起作
在我的 View 中有一个 ItemsControl,它绑定(bind)到来自 ViewModel 的 ObservableCollection。集合被填充,然后引发从 VM 到 View 的事件(想
我最近遇到了一个虚拟化问题,我将其缩小到以下代码。 虚拟化在以下代码段中不起作用的原因是因为 child 没有特定的高度。所以我的猜测是它会永远扩展并且虚拟化会中断。 给 child 一个特定的高度解
我是 WPF 的新手。我一直在尝试执行以下操作: 以下是我的数据结构: public class TokenItems {public string items {get;set;} public i
我正在尝试从 WPF MVVM 教程中扩展应用程序作为练习。对于我在这里面临的这个特定问题,我在网上没有找到解决方案。 我有一个名为“StudentsToAdd”的带有 ObservableColle
我正在使用带有 MVVM 模式的 Wpf,所以在 Xamel 中,我有一个 itemControl 持有另一个 itemcontrol,每个 itemcontrol 绑定(bind)来自不同的 Obs
标题可能听起来令人费解,但请耐心等待。 我有包含住户的房间: public class Room { public string Name { get; set; } public L
我需要能够从子 ItemsControll 数据模板内部绑定(bind)到父 ItemsControl 的属性:
这让我发疯。也许我的数据设计有误,但我正在尝试从父 ItemsControl 绑定(bind)到事件项目。 每个区域都有一种颜色,以便在屏幕上轻松识别。我没有为每个座位赋予颜色属性,而是在 Area
我的问题与此非常相似:( Binding events to buttons in an ItemsControl ) 但我没有在那里找到解决方案。我有一个 ItemsControl,在它的 Data
考虑以下 XAML
在我的主视图中,我有一个绑定(bind)到对象集合的 ItemsControl: ActivationLevelTemplate 只是另一个 View : 在这个 View 中有一
我正在使用 ItemsControl,其中 ItemsPanel 设置为 Canvas(有关更多背景信息,请参阅 this 问题)。ItemsControl 正在按我想要的方式执行,并且通过将子元素放
我有一个 ScrollViewer,里面有一个 ItemsControl。 ItemsControl 的 ItemSource 绑定(bind)到 ObservableCollection。 问题是它
我有一个带有 itemscontrol 的 WPF MVVM 应用程序。水平子项的数量受 itemscontrol 宽度的影响。只有一件事我没有解决。我试图以始终居中的方式对齐子元素。我已经用油漆制作
我有以下 XAML: 当我将数据拖到此面板上时,鼠标光标显示允许在所有子项上放置,但在任何空白区域上,光标显示禁止放置。如果我设置 AllowDro
我有一些数据要显示在 FlowDocument 中.这基本上是一个以友好方式解释数据的 View ,包括节标题、文本段落等,我将在 FlowDocumentScrollViewer 中显示这些 Vie
我有一个 ItemsControl包含我想虚拟化的数据列表,但是 VirtualizingStackPanel.IsVirtualizing="True"似乎不适用于 ItemsControl . 真
我想写一个 ItemsControl 派生的自定义控件。这部分是出于需要,部分是作为学习练习 - 请不要建议 I Style、DataTemplate、ControlTemplate 和 ListBo
我想使用ItemsControl显示重要的项目列表。 我使用ItemsControl的原因是,我正在处理的应用程序中的DataTemplate要复杂得多:提供的示例代码仅反射(reflect)了我的大
我是一名优秀的程序员,十分优秀!