我创建了一个PowerShell GUI,该GUI结合了2个pdf文档,然后将其转换为.tif
,然后重命名,最后将其移至最终位置。
如果可能的话,我想使用ListBox来显示上述脚本的操作
因此,在第一个ListBox中,它需要显示将要组合的2个pdf文件。
我似乎无法显示任何文件!
$listBox1_SelectedIndexChanged = {
$listBox1.Text = Get-ChildItem "E:\SIGNEDNOTES" -Filter *.pdf
}
$listBox1_SelectedIndexChanged = {
$rootFolder = "E:\SIGNEDNOTES\"
$subfolders = (Get-ChildItem -Path $rootFolder -Filter *.pdf -Recurse -Directory).FullName
$listBox1 = New-Object System.Windows.Forms.ListBox
$listBox1.Items.AddRange($subfolders)
}
要将新项目添加到中,ListBox
您需要填充ListBox.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>
我假设您已经有了在PowerShell中使用XAML布局的方法,但如果没有,则可以使用本博客文章“在PowerShell中使用GUI元素”中介绍的方法。
我listBox
叫$WPFlistBox
,所以这是我的填充方式。
$items = get-childItem c:\temp\*.exe
ForEach($item in $items){
$WPFlistBox.Items.Add($item.FullName)
}
只需更改变量以匹配您自己的变量,就可以顺利进行。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句