【发布时间】:2020-10-22 20:05:20
【问题描述】:
我正在尝试获取按姓氏属性搜索的用户列表并将其列在 ListView 中。
这是 XAML 代码:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Title="Find users with SamAccountName"
Width="525"
Background="#FF262626"
ResizeMode="NoResize"
SizeToContent="Height">
<StackPanel Margin="5,5,5,5" Orientation="Vertical">
<Grid
Name="Grid"
Width="400"
Height="200"
Background="#313130">
<Label
Name="Label"
Content="Select employee"
FontSize="12"
Foreground="White" />
<ListView
Name="ListView"
Margin="0,25,0,0"
Background="Transparent"
BorderBrush="Transparent"
Foreground="White"
IsHitTestVisible="False"
SelectionMode="Single">
<ListView.View>
<GridView>
<GridViewColumn
Width="100"
DisplayMemberBinding="{Binding Path=Logon}"
Header="Logon" />
<GridViewColumn
Width="150"
DisplayMemberBinding="{Binding Path=FirstName}"
Header="First name" />
<GridViewColumn
Width="150"
DisplayMemberBinding="{Binding Path=LastName}"
Header="Last name" />
</GridView>
</ListView.View>
</ListView>
</Grid>
<StackPanel HorizontalAlignment="Right">
<Button Width="50" Content="SAVE" />
</StackPanel>
</StackPanel>
它看起来像这样: XAML look
我相信如果没有数据绑定我就无法做到这一点,我看到了很多关于它们的帖子,但我无法完全理解。
现在在 powershell 中我有:
Add-Type -AssemblyName PresentationFramework
$employees = Get-ADUser -Filter {Surname -like "surname"}
$itemSource = @()
ForEach ($employee in ($employees | Sort-Object SamAccountName)) {
$itemSource += [PSCustomObject]@ {
Logon = $employee.Name
FirstName = $employee.GivenName
LastName = $employee.Surname
}
$columnOrder = 'Logon', 'FirstName', 'LastName'
[XML]$Form = Get-Content "xmlPath"
$NR = (New-Object System.Xml.XmlNodeReader $Form)
$Win = [Windows.Markup.XamlReader]::Load($NR)
$Win.ShowDialog()
现在,ForEach 工作得非常好,并且完全返回了我需要的内容,但找不到任何方法将其放入 ViewList。
然后我需要将选定的用户保存到稍后在文本框中显示的变量中。
对不起,如果这是一个愚蠢/简单的问题,但我刚刚开始学习 PowerShell 来帮助我自动化我的工作。
【问题讨论】:
标签: wpf powershell xaml