.net 在powershell中拍摄整个可滚动wpf listview的屏幕截图?

.net 在powershell中拍摄整个可滚动wpf listview的屏幕截图?,.net,wpf,powershell,listview,screenshot,.net,Wpf,Powershell,Listview,Screenshot,我有一个带有自定义图标和图像的Powershell WPF列表视图。希望拍摄整个listview的屏幕截图(同时捕捉图标/图像),即使listview内容由于行数太多而可滚动 有了这样的代码,我只能截图一个特定区域(这里是1000x900px) 找到了一些这样的文章 但没有“仅powershell”方式的代码 另一种方法:将listview转换为xml,然后添加css类,最后导出为html: # HTML formatting $head = @" <style> BODY{back

我有一个带有自定义图标和图像的Powershell WPF列表视图。希望拍摄整个listview的屏幕截图(同时捕捉图标/图像),即使listview内容由于行数太多而可滚动

有了这样的代码,我只能截图一个特定区域(这里是1000x900px)

找到了一些这样的文章
但没有“仅powershell”方式的代码

另一种方法:将listview转换为xml,然后添加css类,最后导出为html:

# HTML formatting
$head = @"
<style>
BODY{background-color:white;}
TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH{border-width: 1px;padding: 5px;border-style: solid;border-color: black;foreground-color: black;background-color: LightBlue}
TD{border-width: 1px;padding: 5px;border-style: solid;border-color: black;foreground-color: black;background-color: white}
.status1{width:80px;height:18px;background-image: url('C:/Programdata/ZPTInfo/Icons/status1.gif');background-repeat:no-repeat;background-size:80px 18px;}
.status3{width:80px;height:18px;background-image: url('C:/Programdata/ZPTInfo/Icons/status3.gif');background-repeat:no-repeat;background-size:80px 18px;}
.status8{width:80px;height:18px;background-image: url('C:/Programdata/ZPTInfo/Icons/status8.gif');background-repeat:no-repeat;background-size:80px 18px;}
.status9{width:80px;height:18px;background-image: url('C:/Programdata/ZPTInfo/Icons/status9.gif');background-repeat:no-repeat;background-size:80px 18px;}
.status81{width:80px;height:18px;background-image: url('C:/Programdata/ZPTInfo/Icons/status81.gif');background-repeat:no-repeat;background-size:80px 18px;}
.status91{width:80px;height:18px;background-image: url('C:/Programdata/ZPTInfo/Icons/status91.gif');background-repeat:no-repeat;background-size:80px 18px;}
</style>
"@

$filedate=Get-Date -UFormat '%m-%d-%Y-%H%M%S'
$filename = "C:\Temp\export_" + $filedate + ".htm"
#$filename = "C:\Temp\export_.htm"

# Convert the selection to an XML object
[xml]$xmlObject = $WPFergebnisse.items | select-Object Ebene,Typ,Pos,Identnr,BENr,Bez,AGKurz,Menge,Status,letzterm,einkaufskz,zusatz | ConvertTo-Html -Fragment

# Parse XML object and set colour class according to value in 4th last column
for($i=1;$i -le $xmlObject.table.tr.count-1;$i++) {
    switch($xmlObject.table.tr[$i].td[-4] -as [int]){
        1 { $xmlObject.table.tr[$i].ChildNodes[($xmlObject.table.tr[$i].ChildNodes.Count-4)].SetAttribute('class','status1') }
        3 { $xmlObject.table.tr[$i].ChildNodes[($xmlObject.table.tr[$i].ChildNodes.Count-4)].SetAttribute('class','status3') }
        8 { $xmlObject.table.tr[$i].ChildNodes[($xmlObject.table.tr[$i].ChildNodes.Count-4)].SetAttribute('class','status8') }
        9 { $xmlObject.table.tr[$i].ChildNodes[($xmlObject.table.tr[$i].ChildNodes.Count-4)].SetAttribute('class','status9') }
        81 { $xmlObject.table.tr[$i].ChildNodes[($xmlObject.table.tr[$i].ChildNodes.Count-4)].SetAttribute('class','status81') }
        91 { $xmlObject.table.tr[$i].ChildNodes[($xmlObject.table.tr[$i].ChildNodes.Count-4)].SetAttribute('class','status91') }
    } 
}

# Define body and append the modified XML object
$body = @"
<H5>Generiert am:  $filedate</H5>
$($xmlObject.innerxml)
"@

# Convert to HTML and save the file
ConvertTo-Html -Head $head -Body $body | Out-File $filename
#HTML格式
$head=@“
正文{背景色:白色;}
表{边框宽度:1px;边框样式:实心;边框颜色:黑色;边框折叠:折叠;}
{边框宽度:1px;填充:5px;边框样式:纯色;边框颜色:黑色;前景色:黑色;背景色:浅蓝色}
TD{边框宽度:1px;填充:5px;边框样式:纯色;边框颜色:黑色;前景色:黑色;背景色:白色}
.status1{宽度:80px;高度:18px;背景图像:url('C:/Programdata/zpInfo/Icons/status1.gif');背景重复:无重复;背景大小:80px 18px;}
.status3{宽度:80px;高度:18px;背景图像:url('C:/Programdata/zpInfo/Icons/status3.gif');背景重复:无重复;背景大小:80px 18px;}
.status8{宽度:80px;高度:18px;背景图像:url('C:/Programdata/zpInfo/Icons/status8.gif');背景重复:无重复;背景大小:80px 18px;}
.status9{宽度:80px;高度:18px;背景图像:url('C:/Programdata/zpInfo/Icons/status9.gif');背景重复:无重复;背景大小:80px 18px;}
.status81{宽度:80px;高度:18px;背景图像:url('C:/Programdata/zpInfo/Icons/status81.gif');背景重复:无重复;背景大小:80px 18px;}
.status91{宽度:80px;高度:18px;背景图像:url('C:/Programdata/zpInfo/Icons/status91.gif');背景重复:无重复;背景大小:80px 18px;}
"@
$filedate=获取日期-U格式“%m-%d-%Y-%H%m%S”
$filename=“C:\Temp\export\+$filedate+.htm”
#$filename=“C:\Temp\export\uuux.htm”
#将所选内容转换为XML对象
[xml]$xmlObject=$WPFergebnisse.items |选择对象Ebene、Typ、Pos、identr、BENr、Bez、AGKurz、Menge、Status、letzterm、einkaufskz、zusatz |转换为Html-片段
#解析XML对象并根据最后第四列中的值设置颜色类
对于($i=1;$i-le$xmlObject.table.tr.count-1;$i++){
开关($xmlObject.table.tr[$i].td[-4]-as[int]){
1{$xmlObject.table.tr[$i].ChildNodes[($xmlObject.table.tr[$i].ChildNodes.Count-4)].SetAttribute('class','status1')}
3{$xmlObject.table.tr[$i].ChildNodes[($xmlObject.table.tr[$i].ChildNodes.Count-4)].SetAttribute('class','status3')一词)
8{$xmlObject.table.tr[$i].ChildNodes[($xmlObject.table.tr[$i].ChildNodes.Count-4)].SetAttribute('class','status8')的
9{$xmlObject.table.tr[$i].ChildNodes[($xmlObject.table.tr[$i].ChildNodes.Count-4)].SetAttribute('class','status9')}
81{$xmlObject.table.tr[$i].ChildNodes[($xmlObject.table.tr[$i].ChildNodes.Count-4)].SetAttribute('class','status81')}
91{$xmlObject.table.tr[$i].ChildNodes[($xmlObject.table.tr[$i].ChildNodes.Count-4)].SetAttribute('class','status91')一词)
} 
}
#定义正文并附加修改后的XML对象
$body=@“
Generiert am:$filedate
$($xmlObject.innerxml)
"@
#转换为HTML并保存文件
转换为Html-Head$Head-Body$Body | Out文件$filename

另一种方法:将listview转换为xml,然后添加一些自定义css类,最后将其转换为html
# HTML formatting
$head = @"
<style>
BODY{background-color:white;}
TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH{border-width: 1px;padding: 5px;border-style: solid;border-color: black;foreground-color: black;background-color: LightBlue}
TD{border-width: 1px;padding: 5px;border-style: solid;border-color: black;foreground-color: black;background-color: white}
.status1{width:80px;height:18px;background-image: url('C:/Programdata/ZPTInfo/Icons/status1.gif');background-repeat:no-repeat;background-size:80px 18px;}
.status3{width:80px;height:18px;background-image: url('C:/Programdata/ZPTInfo/Icons/status3.gif');background-repeat:no-repeat;background-size:80px 18px;}
.status8{width:80px;height:18px;background-image: url('C:/Programdata/ZPTInfo/Icons/status8.gif');background-repeat:no-repeat;background-size:80px 18px;}
.status9{width:80px;height:18px;background-image: url('C:/Programdata/ZPTInfo/Icons/status9.gif');background-repeat:no-repeat;background-size:80px 18px;}
.status81{width:80px;height:18px;background-image: url('C:/Programdata/ZPTInfo/Icons/status81.gif');background-repeat:no-repeat;background-size:80px 18px;}
.status91{width:80px;height:18px;background-image: url('C:/Programdata/ZPTInfo/Icons/status91.gif');background-repeat:no-repeat;background-size:80px 18px;}
</style>
"@

$filedate=Get-Date -UFormat '%m-%d-%Y-%H%M%S'
$filename = "C:\Temp\export_" + $filedate + ".htm"
#$filename = "C:\Temp\export_.htm"

# Convert the selection to an XML object
[xml]$xmlObject = $WPFergebnisse.items | select-Object Ebene,Typ,Pos,Identnr,BENr,Bez,AGKurz,Menge,Status,letzterm,einkaufskz,zusatz | ConvertTo-Html -Fragment

# Parse XML object and set colour class according to value in 4th last column
for($i=1;$i -le $xmlObject.table.tr.count-1;$i++) {
    switch($xmlObject.table.tr[$i].td[-4] -as [int]){
        1 { $xmlObject.table.tr[$i].ChildNodes[($xmlObject.table.tr[$i].ChildNodes.Count-4)].SetAttribute('class','status1') }
        3 { $xmlObject.table.tr[$i].ChildNodes[($xmlObject.table.tr[$i].ChildNodes.Count-4)].SetAttribute('class','status3') }
        8 { $xmlObject.table.tr[$i].ChildNodes[($xmlObject.table.tr[$i].ChildNodes.Count-4)].SetAttribute('class','status8') }
        9 { $xmlObject.table.tr[$i].ChildNodes[($xmlObject.table.tr[$i].ChildNodes.Count-4)].SetAttribute('class','status9') }
        81 { $xmlObject.table.tr[$i].ChildNodes[($xmlObject.table.tr[$i].ChildNodes.Count-4)].SetAttribute('class','status81') }
        91 { $xmlObject.table.tr[$i].ChildNodes[($xmlObject.table.tr[$i].ChildNodes.Count-4)].SetAttribute('class','status91') }
    } 
}

# Define body and append the modified XML object
$body = @"
<H5>Generiert am:  $filedate</H5>
$($xmlObject.innerxml)
"@

# Convert to HTML and save the file
ConvertTo-Html -Head $head -Body $body | Out-File $filename