在视图中绘制用户控件。 [英] Draw usercontrol when is in view.
问题描述
我正在开发一个WPF MVVM项目,我有一个显示一些统计信息的用户控件。此用户控件嵌入在列表框中。通常我在列表框中加载大约400到500个用户控件对象。当我加载大约400到500个用户控件实例时,通常需要更多时间来加载。现在我想加载视图中的项目。
注意:我不能使用VirtualizingPanel.VirtualizationMode,因为根据客户要求,项目不应显示在下面另一个。他希望它像网格一样。为了达到这个目的,我在列表框的项目面板中使用了包装面板。
列表框代码:
I am working on a WPF MVVM project where i have a user control which displays some statistics. This user control is embedded in the listbox. usually i load around 400 to 500 objects of user control in the listbox. As i load around 400 to 500 instances of user control it usually takes more time to load. Now i want to load items which are present in the view.
Note: i can not use VirtualizingPanel.VirtualizationMode because as per client requirement the items should not display one below another. He wants it to be like grid. To achieve this i am using wrap panel inside items panel of listbox.
Listbox code:
<ListBox Name="lvDataBinding" SelectionMode="Single" ItemsSource="{Binding AllTiles}" VirtualizingPanel.VirtualizationMode="Recycling">
<ListBox.ItemsPanel >
<ItemsPanelTemplate>
<WrapPanel Width="{Binding (FrameworkElement.ActualWidth),
RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}">
</WrapPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<custom:TileControl Margin="10" DataContext="{Binding}"/>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemContainerStyle>
<Style>
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="Transparent"/>
</Style.Resources>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Expander Header="{Binding}" IsExpanded="True">
<Expander.HeaderTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Background="Transparent">
<TextBlock Text="{Binding Name}" TextBlock.FontSize="20" />
</StackPanel>
</DataTemplate>
</Expander.HeaderTemplate>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListBox.GroupStyle>
</ListBox>
我如何绘制视图中的项目?
因为它违反了我的公司政策,我无法添加完整的源代码。
我是什么尝试过:
尝试虚拟化面板属性,但只有当面板是堆栈面板时才会起作用
How can i draw items which are present in view?
As it violates my company policy i can not add complete source code.
What I have tried:
Tried virtualizing panel property but it will work only if the panel is stack panel
推荐答案
C# - 将WrapPanel虚拟化为ListView的ItemsTemplate - Stack Overflow [ ^ ]
这篇关于在视图中绘制用户控件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!