很容易解释,但很难找到答案。
在下面的代码中,将打开一个漂亮的漂亮框,当您选择一行时,将出现一个包含更多数据的子行。 我想做的是访问子行标题。
[void][System.Reflection.Assembly]::LoadWithPartialName( 'presentationframework' )
[xml]$XAML = @'
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Title="Global Core Desktop Toolbox" Height="550" Width="800" WindowStartupLocation="CenterScreen"
WindowStyle="ToolWindow">
<Grid>
<Grid Background="#FF0A2F64">
<DataGrid Name="Datagrid" AutoGenerateColumns="True" HorizontalAlignment="Left" VerticalAlignment="Top"
Height="250" Width="675" Margin="40,125,0,0" Visibility="Visible" IsReadOnly="True" >
<DataGrid.Columns>
<DataGridTextColumn Header="Domain" Binding="{Binding Domain}" Width="Auto" />
<DataGridTextColumn Header="Total Live PCs" Binding="{Binding LiveMachines}" Width="Auto"/>
<DataGridTextColumn Header="DR" Binding="{Binding DR}" Width="40"/>
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<DockPanel Background="GhostWhite">
<Grid Margin="0,10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Text="Domain: " FontWeight="Bold" Grid.Row="1" />
<TextBlock Text="{Binding Domain}" Grid.Column="1" Grid.Row="1" />
<TextBlock Text="Disabled Machines: " FontWeight="Bold" Grid.Row="2" />
<TextBlock Text="{Binding SamAccountDisabled}" Grid.Column="1" Grid.Row="2" />
<TextBlock Text="Servers: " FontWeight="Bold" Grid.Row="3" />
<TextBlock Text="{Binding Servers}" Grid.Column="1" Grid.Row="3" />
</Grid>
</DockPanel>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
</Grid>
</Grid>
</Window>
'@
#Read XAML
$READER = ( New-Object System.Xml.XmlNodeReader $XAML )
Try {
$FORM = [Windows.Markup.XamlReader]::Load( $READER )
}
Catch {
Write-Host "Unable to load Windows.Markup.XamlReader."
Sleep 4
}
$XAML.SelectNodes( "//*[@Name]" ) | %{ Set-Variable -Name ( $_.Name ) -Value
$FORM.FindName( $_.Name ) }
$datagrid.AddChild( [pscustomobject]@{
Domain = "happytimes.local"
LiveMachines = 6
DR = 1
Servers = 2
SamAccountDisabled = 3
} )
$form.ShowDialog()
因此,如果我执行$datagrid.Columns.header
,则可以访问“域”,“总活动PC”和“ DR”-我在foreach循环中使用它们。我要尝试的是“域”,“禁用的机器”和“服务器”。 $datagrid.items
用数字给了我一切,但我无法进一步细分。
我想念什么吗?有什么想法可以找到变量吗?
谢谢