我注意到当我看到ListBox时,我的应用程序不断使用大约15%的CPU。
我尝试过使用Redgate的ANTS性能分析器,但我没有找到这种CPU使用的起源。什么都没有更新,所以我觉得这很奇怪。
以下是ListBox的XAML代码:
<ListBox x:Name="MusicList" ItemsSource="{Binding}" MouseDoubleClick="MusicList_MouseDoubleClick" PreviewMouseWheel="MusicList_PreviewMouseWheel" PreviewMouseLeftButtonDown="MusicList_PreviewMouseLeftButtonDown" TextSearch.TextPath="name" KeyDown="MusicList_KeyDown" Background="#3F181818" Margin="0,175,0,0" BorderThickness="0,1,0,0" ScrollViewer.HorizontalScrollBarVisibility="Hidden" BorderBrush="#FF282828">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="88">
<Border Height="64" Width="64" Margin="12,12,0,12">
<Image Stretch="UniformToFill" Source="{Binding Path=album.albumart, IsAsync=True}"/>
</Border>
<StackPanel Orientation="Vertical" VerticalAlignment="Top" Margin="0,10,0,0">
<TextBlock Text="{Binding Path=name, IsAsync=True, Mode=OneTime}"
Margin="10,0,0,0" Width="300" Height="40"
TextTrimming="WordEllipsis" TextWrapping="Wrap"
FontSize="16" HorizontalAlignment="Left"
Foreground="White"/>
<TextBlock Text="{Binding Path=album.name, IsAsync=True, Mode=OneTime}"
Margin="10,-15,0,0" Width="300" Height="20"
TextTrimming="WordEllipsis"
HorizontalAlignment="Left"
FontSize="14" Opacity="0.49" Foreground="White"/>
<TextBlock Text="{Binding Path=artistname, IsAsync=True, Mode=OneTime}"
Margin="10,2,0,0" Width="300"
TextTrimming="WordEllipsis"
HorizontalAlignment="Left"
FontSize="12" Opacity="0.49" Foreground="White"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我在列表框本身中有大约500个项目,但我认为DataViritualization已启用,因为滚动使得它看起来像正在绘制新项目。
有谁知道为什么会这样?