wpf - 在执行 ComboBox 任务时显示进度条
问题描述
在 ComboBox 中选择项目时,会复制一些与所选名称匹配的文件。这需要一些时间,并且在此期间屏幕只是冻结(列表下拉),我希望下拉的组合框列表上升并在复制文件时显示进度条。我尝试添加一个进度条,但它没有显示出来。
$ComboBox.Add_SelectionChanged(
{
$progressBar.Visibility = "Visible" #Show an Indeterminate Progress Bar at the beginning
if($ComboBox.SelectedItem)
{
$selectedName = $ComboBox.SelectedItem
Copy-Item -Path $storePath\* -Destination $tempPath -Filter $selectedName*
$fileList = (Get-ChildItem -Path $tempPath).Name | Select-String $selectedName
$ListBox.Items.Clear()
foreach($file in $fileList)
{
$ListBox.Items.Add($fileList)
}
}
$progressBar.Visibility = "Hidden" #Hide the Progress Bar once done
})
解决方案
作为一种解决方法,我使用“DropDownClosed”触发复制,同时使用“SelectionChanged”触发进度条。现在的问题是进度条卡住了。现在我需要另一种方法在单独的线程中运行 ProgressBar。
$ComboBox.Add_SelectionChanged(
{
$progressBar.Visibility = "Visible" #Show an Indeterminate Progress Bar at the beginning
})
$ComboBox.Add_DropDownClosed(
{
if($ComboBox.SelectedItem)
{
$selectedName = $ComboBox.SelectedItem
if(!((Get-ChildItem -Path $tempPath).Name | Select-String $selectedName))
{
Copy-Item -Path $storePath\* -Destination $tempPath -Filter $selectedName*
}
$fileList = (Get-ChildItem -Path $tempPath).Name | Select-String $selectedName
$ListBox.Items.Clear()
foreach($file in $fileList)
{
$ListBox.Items.Add($fileList)
}
}
$progressBar.Visibility = "Hidden" #Hide the Progress Bar once done
})
推荐阅读
- json - 反序列化一个简单的 JSON 数组
- r-markdown - 使用 RMarkdown 和 pandoc(类似于投影仪讲义的系统)编译 HTML 演示文稿时隐藏文本元素
- flutter - flutter : willpopscope, 返回类型 'future
'不是'未来 - deep-learning - 具有内部 IP 地址且无 SSH 访问权限的 DataProc HUB 实例
- c# - C# MongoDb 驱动程序使用空值更新子文档
- javascript - node环境执行渲染测试报错:unexpected token after conditional expression
- android - 我可以将特定端口分配给我的 android 模拟器吗
- javascript - 动态生成的下拉列表不显示选项
- c++ - 为什么尽管指针的 int 加法比通过指针的 int 乘法少一条 x86 指令?
- python - curl为多个字符串输入返回单个输出