【发布时间】:2016-05-05 00:49:27
【问题描述】:
我的问题是我需要在 WPF 中的 Listview 中添加很多项目。在 WinForms 中,您只需使用 BeginUpdate() 方法,添加所有内容,最后使用 EndUpdate() 方法。
那么,如何在 WPF Listview 中停止绘图,直到添加每个项目,然后一次性绘制所有内容?
foreach (FilePaths filePath in directoryPath.GetFilePaths())
{
GetFileListViewItem(filePath);
}
在这个GetFileListViewItem 方法中,我将项目添加到列表视图。
private void GetFileListViewItem(FilePaths filePath)
{
string ext = GetExtension(filePath.GetPath());
string fileName = GetFileNameWithoutExtension(filePath.GetPath());
string type = "";
if (ext != "")
{
type = ext.ToUpper().Substring(1) + " File";
}
else
{
type = "Unknown";
}
fileListView.Items.Add(new FileListItem
{
Name = fileName,
Type = type
});
}
【问题讨论】:
-
您正在使用的代码?
-
@ChrisBint - 更新
-
但这不会一次绘制一个项目。在该调用(和其他调用)完成之前,不会刷新 UI。在绘制 UI 之前,会 100% 处理后面的代码。现在您生成的 UI 更改事件超出了您的需要,但 UI 只绘制了一次。
标签: c# wpf listview listviewitem