积极答复者
WPF VirtualizlingStackPanel容器中添加控件不显示问题

问题
-
突然发现了这么一高级获VirtualizlingStackPanel,ComboBox的模板改成VirtualizlingStackPanel后加载大量数据时很有效果,我想向VirtualizlingStackPanel容器中添加控件如:
<VirtualizingStackPanel Orientation="Vertical" Width="200" Height="100" Margin="234,276,123,0" Name="vsp" Background="Azure" >
<Border Width="20" Height="20" Background="Red" VirtualizingStackPanel.IsVirtualizing="False"/>
<Border Width="20" Height="20" Background="Red"/>
<Border Width="20" Height="20" Background="Red"/>
<Border Width="20" Height="20" Background="Red"/>
<Border Width="20" Height="20" Background="Red"/>
<Border Width="20" Height="20" Background="Red"/>
<Border Width="20" Height="20" Background="Red"/>
</VirtualizingStackPanel>为什么不显示?这玩意儿怎么用?
答案
-
你好,
VirtualizingStackPanel 类 是用来将内容排列和虚拟化在一行上,方向为水平或垂直。
虚拟化是指一种技术,通过该技术,可根据屏幕上所显示的项从大量数据项中生成 UI 元素的子集。 VirtualizingStackPanel 会计算可见项的数量,并处理来自 ItemsControl(如 ListBox)的 ItemContainerGenerator,以便只为可见项创建 UI 元素。
你的代码不显示的原因是:在 XAML 中使用,VirtualizingStackPanel 对象元素必须包含在一个 ItemsPanelTemplate 中。
关于它的用法,你可以参考MSDN文档:http://msdn.microsoft.com/zh-cn/library/system.windows.controls.virtualizingstackpanel(v=vs.95).aspx
Lisa Zhu [MSFT]
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已编辑 Lisa ZhuModerator 2013年2月28日 6:11
- 已标记为答案 Lisa ZhuModerator 2013年3月10日 4:24
-
你把VirtualizingStackPanel设置为容器的ItemsPanel属性的值,然后把你要显示的东西设置为容器的Items。
例如
<ComboBox>
<ComboBox.ItemsPanel> <VirtualizingStackPanel> </ComboBox.ItemsPanel>
</ComboBox>
然后把Border们加入到ComboBox的Items里面。
如果你想让每个Item里面显示一个红色的Border,则做一个特殊的ItemTemplate,或者直接把一个视觉元素作为Items里面的元素。
- 已标记为答案 Lisa ZhuModerator 2013年3月10日 4:24
全部回复
-
你好,
VirtualizingStackPanel 类 是用来将内容排列和虚拟化在一行上,方向为水平或垂直。
虚拟化是指一种技术,通过该技术,可根据屏幕上所显示的项从大量数据项中生成 UI 元素的子集。 VirtualizingStackPanel 会计算可见项的数量,并处理来自 ItemsControl(如 ListBox)的 ItemContainerGenerator,以便只为可见项创建 UI 元素。
你的代码不显示的原因是:在 XAML 中使用,VirtualizingStackPanel 对象元素必须包含在一个 ItemsPanelTemplate 中。
关于它的用法,你可以参考MSDN文档:http://msdn.microsoft.com/zh-cn/library/system.windows.controls.virtualizingstackpanel(v=vs.95).aspx
Lisa Zhu [MSFT]
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已编辑 Lisa ZhuModerator 2013年2月28日 6:11
- 已标记为答案 Lisa ZhuModerator 2013年3月10日 4:24
-
你把VirtualizingStackPanel设置为容器的ItemsPanel属性的值,然后把你要显示的东西设置为容器的Items。
例如
<ComboBox>
<ComboBox.ItemsPanel> <VirtualizingStackPanel> </ComboBox.ItemsPanel>
</ComboBox>
然后把Border们加入到ComboBox的Items里面。
如果你想让每个Item里面显示一个红色的Border,则做一个特殊的ItemTemplate,或者直接把一个视觉元素作为Items里面的元素。
- 已标记为答案 Lisa ZhuModerator 2013年3月10日 4:24