3

Consider the following code:

$a = @()

$b = "" |select ho_ho,ha_ha
$b.ho_ho = "1"
$b.ha_ha = "2"
$a+=$b

$b = "" |select ho_ho,ha_ha
$b.ho_ho = "3"
$b.ha_ha = "4"
$a+=$b

$a | Format-Table -AutoSize
$a | Out-GridView

Using Format-Table, the underscores on the column headers are retained.

ho_ho ha_ha
----- -----
1     2
3     4

However, when using Out-Gridview, the underscores are automatically removed?

Underscores removed

Does anyone know how to avoid this?

4

1 回答 1

2

这似乎与 WPF 中的事实有关,即文本中的第一个下划线作为控件的加速字符的前缀。

有关详细信息,请参阅此博客文章

WPF 使用下划线字符而不是 & 字符(与 WinForms 一样)在其元素(如标签和按钮)的文本中为访问键(也称为加速键或助记符)添加前缀。

您可以使用两个下划线来转义下划线。

所以这段代码会在 gridview 中显示 Ok 但不会在Format-Table输出中显示

$a = @()

$b = "" |select ho__ho,ha__ha
$b.ho__ho = "1"
$b.ha__ha = "2"
$a+=$b

$b = "" |select ho__ho,ha__ha
$b.ho__ho = "3"
$b.ha__ha = "4"
$a+=$b

$a | Format-Table -AutoSize
$a | Out-GridView

请注意,只有在字符串中的第一个下划线需要转义,其他下划线不需要转义。

我认为这可能被视为一个错误(因为它实际上也没有添加任何快捷键),但我在http://connect.microsoft.com上找不到任何报告

于 2017-01-19T20:39:17.107 回答