Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 执行组合框任务时显示进度条_Wpf_Powershell - Fatal编程技术网

Wpf 执行组合框任务时显示进度条

Wpf 执行组合框任务时显示进度条,wpf,powershell,Wpf,Powershell,在组合框中选择项目时,将复制与所选名称匹配的某些文件。这需要一些时间,屏幕只是冻结与下拉列表在此期间,我想下拉组合框列表上升,并显示一个进度条,而文件得到复制。我尝试添加一个进度条,但它没有显示 $ComboBox.Add_SelectionChanged( { $progressBar.Visibility = "Visible" #Show an Indeterminate Progress Bar at the beginning if

在组合框中选择项目时,将复制与所选名称匹配的某些文件。这需要一些时间,屏幕只是冻结与下拉列表在此期间,我想下拉组合框列表上升,并显示一个进度条,而文件得到复制。我尝试添加一个进度条,但它没有显示

$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
})

您需要为此添加另一个元素,并且需要对预期的集合进行计算。因此,你必须收集你所需要的,以计算工作进度。在网上和Youtube视频上都有这样的例子。