Memory 如何检查itemscontrol项是否在视口中
我正在创建wp8应用程序,并通过itemscontrol控件来表示一个大数据集。问题是,由于元素的大小,我丢失了很多内存。如何检查itemscontrol项是否在视口中Memory 如何检查itemscontrol项是否在视口中,memory,optimization,windows-phone-8,viewport,itemscontrol,Memory,Optimization,Windows Phone 8,Viewport,Itemscontrol,我正在创建wp8应用程序,并通过itemscontrol控件来表示一个大数据集。问题是,由于元素的大小,我丢失了很多内存。如何检查itemscontrol项是否在视口中 <ItemsControl x:Name="showList" Margin="0" ItemsSource="{Binding tmp}"> <ItemsControl.ItemsPanel>
<ItemsControl x:Name="showList" Margin="0" ItemsSource="{Binding tmp}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"></StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,2,0,0" Background="#FF2E2E2E" Width="280">
<Image Source="../Images/edge_shadow_x8.png" HorizontalAlignment="Left" Stretch="Fill" Width="8" Margin="0,0,2,0"/>
<TextBlock x:Name="time" FontSize="16" Text="{Binding StartTime}" Width="50" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="15,0" Foreground="White" TextWrapping="Wrap"/>
<TextBlock x:Name="show" FontSize="16" Text="{Binding title}" Width="160" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0,5,10,5" TextWrapping="Wrap"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</ScrollViewer>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
以下是我使用的xaml:
<ItemsControl x:Name="showList" Margin="0" ItemsSource="{Binding tmp}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"></StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,2,0,0" Background="#FF2E2E2E" Width="280">
<Image Source="../Images/edge_shadow_x8.png" HorizontalAlignment="Left" Stretch="Fill" Width="8" Margin="0,0,2,0"/>
<TextBlock x:Name="time" FontSize="16" Text="{Binding StartTime}" Width="50" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="15,0" Foreground="White" TextWrapping="Wrap"/>
<TextBlock x:Name="show" FontSize="16" Text="{Binding title}" Width="160" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0,5,10,5" TextWrapping="Wrap"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</ScrollViewer>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
<ItemsControl x:Name="showList" Margin="0" ItemsSource="{Binding tmp}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"></StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,2,0,0" Background="#FF2E2E2E" Width="280">
<Image Source="../Images/edge_shadow_x8.png" HorizontalAlignment="Left" Stretch="Fill" Width="8" Margin="0,0,2,0"/>
<TextBlock x:Name="time" FontSize="16" Text="{Binding StartTime}" Width="50" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="15,0" Foreground="White" TextWrapping="Wrap"/>
<TextBlock x:Name="show" FontSize="16" Text="{Binding title}" Width="160" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0,5,10,5" TextWrapping="Wrap"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</ScrollViewer>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
您能使用LongListSelector控件吗?不幸的是,不能。我正在尝试实现某种ui虚拟化以减少内存消耗,这就是为什么我需要能够访问单个项目并检查其是否在视口中,以便可以操作该项目。谢谢你的评论