Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/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
Visual studio Visual Studio,如何获取要在Listbox Powershell中显示的文件_Visual Studio_Powershell_Listbox - Fatal编程技术网

Visual studio Visual Studio,如何获取要在Listbox Powershell中显示的文件

Visual studio Visual Studio,如何获取要在Listbox Powershell中显示的文件,visual-studio,powershell,listbox,Visual Studio,Powershell,Listbox,我创建了一个PowerShell GUI,它组合了2个pdf文档,然后将其转换为.tif,然后对其重命名,最后将其移动到最终位置 如果可能的话,我想使用一个列表框来显示上述脚本的操作 因此,在第一个列表框中,它需要显示将要合并的2个pdf文件 我似乎无法让它显示任何文件 $listBox1_SelectedIndexChanged = { $listBox1.Text = Get-ChildItem "E:\SIGNEDNOTES" -Filter *.pdf } 要将新项目添加到列

我创建了一个PowerShell GUI,它组合了2个pdf文档,然后将其转换为
.tif
,然后对其重命名,最后将其移动到最终位置

如果可能的话,我想使用一个列表框来显示上述脚本的操作

因此,在第一个列表框中,它需要显示将要合并的2个pdf文件

我似乎无法让它显示任何文件

$listBox1_SelectedIndexChanged = {
    $listBox1.Text = Get-ChildItem "E:\SIGNEDNOTES" -Filter *.pdf
}

要将新项目添加到
列表框
中,您需要填充
列表框.items
集合。这里有一个简单的例子

考虑到这个XAML

<Window x:Class="WpfApp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp1"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <ListBox x:Name="listBox" HorizontalAlignment="Left" Height="138" Margin="84,103,0,0" VerticalAlignment="Top" Width="332"/>

    </Grid>
</Window>
只要更改变量以匹配您自己的变量,您就可以顺利完成任务

下面是一个它看起来像什么的例子。

假设这是windows窗体,您需要将每个项目添加到
$listBox1。项目
感谢您的回复,是的,这是一个windows窗体。你有例子吗please@MathiasR.Jessen我已经编辑了我的问题“我是否走对了道路?”我自己没有做太多基于表单的Powershell C#的工作,但我认为您需要将结果作为一个对象在$subfolders中进行强制转换,而不在C#中添加标题,以便它知道如何解释它。类似于
ListBox1.Items.AddRange(新对象[]{$subfolders}
,我认为在C#中,我们需要使用
this.ListBox1.
来引用该对象,但我实际上只涉猎了这一点,所以这可能是可选的,或者只是动态学习的产物,不需要)谢谢你的评论@BenPersonick我和我的代码是同一条船,但现在它不会在列表框中显示任何东西,所以烦人的Hahay你需要触发逻辑来填充你的列表,现在你在这个事件处理程序中有了逻辑<代码>列表框1\u选择的索引已更改。你在引用这个吗?可以肯定的是,请尝试将列表填充逻辑移到事件处理程序之外,以便由defaulkt运行。谢谢您的帮助,太好了,@FoxDeploy请您再举一个很好的例子,这样我就可以解决这个问题。再次谢谢,祝你好运。你到底要什么?你可以拥有你想要的任何东西,只要它不是该系列中的另一篇博文
<Window x:Class="WpfApp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp1"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <ListBox x:Name="listBox" HorizontalAlignment="Left" Height="138" Margin="84,103,0,0" VerticalAlignment="Top" Width="332"/>

    </Grid>
</Window>
$items = get-childItem c:\temp\*.exe 
ForEach($item in $items){
   $WPFlistBox.Items.Add($item.FullName)
}