Powershell WPF Combobox No Item

时间:2017-10-10 14:50:29

标签: c# wpf powershell combobox

我无法在组合框中添加对象。

我在网上搜索并尝试了几次测试

我认为这一切都很简单......

谢谢!

Add-Type -assemblyName PresentationFramework 
Add-Type -assemblyName PresentationCore 
Add-Type -assemblyName WindowsBase

[xml]$XAML = @’
<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="340" Width="368">
    <Grid>
        <ComboBox Height="28" HorizontalAlignment="Left" Margin="103,52,0,0" Name="comboBox1" VerticalAlignment="Top" Width="158" />
        <Button Content="Exit" Height="39" HorizontalAlignment="Left" Margin="109,203,0,0" Name="button1" VerticalAlignment="Top" Width="118" />
    </Grid>
</Window>
'@

$reader=New-Object System.Xml.XmlNodeReader $xaml 
$Form=[Windows.Markup.XamlReader]::Load($reader)

$Fonction = $Form.FindName('comboBox1')
$Exit = $Form.FindName('button1')
$var = "Test"

$Fonction.Items.add($var)

$Exit.add_click({ $Form.close() })

$Form.ShowDialog() | Out-Null

0 个答案:

没有答案