WPF选项卡控制选项卡项目高CPU使用率
在我的WPF应用程序中,我有一个WPF选项卡控制选项卡项目高CPU使用率,wpf,mvvm,load,cpu,Wpf,Mvvm,Load,Cpu,在我的WPF应用程序中,我有一个TabControl和三个TabItems。每个TabItem都有一个ItemsControl,其中ItemsSource绑定到Viewmodel中的observeCollection。如果我打开第一个和第二个选项卡项,CPU使用率为70%,我不知道为什么 我的第一个想法是,数据绑定导致了这种情况。因此,我从这个选项卡项中删除了所有绑定。但是,即使第三个选项卡item没有被调用的内容或代码,CPU使用率仍然很高。如果我切换回第一个和第二个选项卡项,CPU使用率将恢
TabControl
和三个TabItems
。每个TabItem
都有一个ItemsControl
,其中ItemsSource
绑定到Viewmodel中的observeCollection
。如果我打开第一个和第二个选项卡项
,CPU使用率为70%,我不知道为什么
我的第一个想法是,数据绑定导致了这种情况。因此,我从这个选项卡项中删除了所有绑定。但是,即使第三个选项卡item
没有被调用的内容或代码,CPU使用率仍然很高。如果我切换回第一个和第二个选项卡项
,CPU使用率将恢复正常
<TabControl Grid.Row="1">
<TabItem Header="Tab1" IsSelected="True">
<Grid>
<Grid.Background>
<LinearGradientBrush EndPoint="0.504,1.5" StartPoint="0.504,0.03">
<GradientStop Color="#f0f0f0" Offset="0" />
<GradientStop Color="#DBFFDF" Offset="1" />
</LinearGradientBrush>
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="5" />
<RowDefinition Height="60*" />
<RowDefinition Height="5" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5" />
<ColumnDefinition Width="175" />
<ColumnDefinition Width="15" />
<ColumnDefinition Width="70*" />
<ColumnDefinition Width="5" />
</Grid.ColumnDefinitions>
<Border Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="#F0F0F0" BorderBrush="DarkGray" BorderThickness="3">
<ScrollViewer IsDeferredScrollingEnabled="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<view:Overview />
</ScrollViewer>
</Border>
<Border Grid.Column="3" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="#F0F0F0" BorderBrush="DarkGray" BorderThickness="3">
<ScrollViewer IsDeferredScrollingEnabled="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<ItemsControl ItemsSource="{Binding OverviewElementCollection}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</ScrollViewer>
</Border>
</Grid>
</TabItem>
<TabItem Header="Tab2">
<ScrollViewer IsDeferredScrollingEnabled="True" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<TabControl ItemsSource="{Binding TabItemCollection}" />
</ScrollViewer>
</TabItem>
<TabItem Header="Tab3">
<Grid>
<Grid.Background>
<LinearGradientBrush EndPoint="0.504,1.5" StartPoint="0.504,0.03">
<GradientStop Color="#f0f0f0" Offset="0" />
<GradientStop Color="#DBFFDF" Offset="1" />
</LinearGradientBrush>
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="5" />
<RowDefinition Height="60*" />
<RowDefinition Height="5" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5" />
<ColumnDefinition Width="175" />
<ColumnDefinition Width="15" />
<ColumnDefinition Width="70*" />
<ColumnDefinition Width="5" />
</Grid.ColumnDefinitions>
<Border Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="#F0F0F0" BorderBrush="DarkGray" BorderThickness="3">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
</ScrollViewer>
</Border>
<Border Grid.Column="3" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="#F0F0F0" BorderBrush="DarkGray" BorderThickness="3">
<ScrollViewer IsDeferredScrollingEnabled="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<ItemsControl ItemsSource="{Binding ErrorOverviewElementCollection}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</ScrollViewer>
</Border>
</Grid>
</TabItem>
</TabControl>
所以我希望你能帮助我 第三个选项卡中是否有情节提要或类似动画?没有。我将添加一个示例您是否注意到输出(调试)窗口中有任何异常?我还建议您在CPU使用率上升时单击“暂停”按钮,然后查看线程窗口(Debug/Windows/threads)中可能导致问题的线程。确定输出窗口仅显示:跳过加载符号。模块已优化,并且调试器选项“仅我的代码”已启用。如何查看线程是否导致问题?我知道这个窗口,但我不熟悉它。如果我暂停了主线程,CPU使用率为0。因此,我想其他线程不应对如此高的CPU使用率负责。还是我错了?