我有Listview,显示185列和15行。为了显示包含15行的185列,windows store app需要一些时间或UI被冻结。下面是Im用于显示数据的代码
<ListView x:Name="outerlstView"
Height="650"
Margin="2,24,10,10" Grid.Row="1"
Grid.Column="1" BorderThickness="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
ItemsSource =“{Binding Data,Mode = TwoWay,UpdateSourceTrigger = PropertyChanged}”
ScrollViewer.HorizontalScrollBarVisibility = “可见”
ScrollViewer.HorizontalScrollMode =“已启用”ScrollViewer.VerticalScrollBarVisibility =“Auto”
SelectionMode =“None”ShowsScrollingPlaceholders =“True”IsZoomedInView =“False”
IsSwipeEnabled =“False”IsItemClickEnabled =“False”
ItemContainerStyle =“{StaticResource LvItemStyle}”
Orientation =“Vertical”VirtualizingStackPanel.VirtualizationMode =“Standard”/&gt;
ShowsScrollingPlaceholders = “真” &GT;
Height =“{Binding Path = Tag,RelativeSource = {RelativeSource Mode = Self},Converter = {StaticResource RowtoHeightConverter}}”&gt;
上面的代码里面有listview,里面是另一个listview。当我尝试加载列表&gt;列表视图需要花费太多时间。当我加载包含185列的100行时,应用程序崩溃了一段时间。
我尝试将Itemtemplate stye控件替换为Itemstackpanel,性能良好。数据加载并在屏幕上显示得更快,但我没有看到水平滚动
以前的代码
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel
Orientation="Vertical" VirtualizingStackPanel.VirtualizationMode="Standard"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
当我修改为<ListView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsStackPanel Margin="0,0,0,0" Width="Auto" Orientation="Horizontal" Height="35" VirtualizingStackPanel.VirtualizationMode="Standard"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
我没有看到启用水平滚动条。任何人都可以建议我如何启用默认情况下启用水平滚动条到Windows商店应用程序中的Itemstackpanel。看起来像是这个控件的bug或者使用Horizontal Scrollbar解决ItemsStackpanel。
答案 0 :(得分:1)
如果您的ItensSource是具有属性Name和属性Price的对象列表,例如:
<ListView ItemsSource="{Binding Here_your_DataSource}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Visible" >
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<WrapGrid Orientation="Horizontal" MaximumRowsOrColumns="15"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<!--Here u design your item template-->
<StackPanel Background="Blue" Width="100" Height="100">
<TextBlock Text="{Binding Name}"></TextBlock>
<TextBlock Text="{Binding Price}"></TextBlock>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>