【发布时间】:2013-06-21 05:55:33
【问题描述】:
我一直在 WPF 中处理一个小视图,其中包含几个 Buttons 和一个 ListBox,其项目的模板包含一个 CheckBox 和一个 ContentPresenter。当我开始在ListBox 中滚动时,ScrollBar 会上下移动。这是一种性能问题,我认为这是因为CheckBoxes。我认为CheckBoxes 有某种渲染动画,它需要几毫秒才能在滴答声中淡出,并且运行同步,因此会出现延迟。
我可能是错的,也许是其他原因导致了这个问题。此外,仅作为旁注,因为这对你们来说可能很重要,我在 Intel i5 上的 Windows 7 中运行该应用程序。
当我将CheckBoxs 离开模板时,一切都运行得非常顺利。
你们建议我做什么?
我不知道如何禁用该动画,并且我不想要那种滞后的行为。
编辑:我的 ListBox 中有 5000 个项目
这是我的 XAML:
<ListBox ItemsSource="{Binding Source}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding Checked}"/>
<ContentPresenter Content="{Binding Text}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
这是我的视图模型:
public class ViewModel
{
public ViewModel()
{
this.Source = new ObservableCollection<ListItem>();
for (int i = 0; i < 5000; i++)
{
this.Source.Add(new ListItem(){ Text = "test" + i, Checked = true });
}
}
public ObservableCollection<ListItem> Source
{
get;
set;
}
}
public class ListItem
{
public bool Checked
{
get;
set;
}
public string Text
{
get;
set;
}
}
这是我的 MainWindow.cs:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.DataContext = new ViewModel();
}
}
【问题讨论】:
-
@Anatoliy 发表您的评论作为答案,我会标记它。回收确实有点帮助,谢谢你的建议。 IsDefScrolling 并不是我真正想要的,但我会记住它。
标签: wpf xaml wpf-controls