C# Powershell WPF组合框无项目
我无法在组合框中添加对象 我在网上搜索并尝试了几个测试 我觉得一切都很简单 谢谢大家!C# Powershell WPF组合框无项目,c#,wpf,powershell,combobox,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/x
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
添加类型-assemblyName PresentationFramework
添加类型-assemblyName PresentationCore
添加类型-assemblyName WindowsBase
[xml]$XAML=@'
'@
$reader=New Object System.Xml.XmlNodeReader$xaml
$Form=[Windows.Markup.XamlReader]::加载($reader)
$Fonction=$Form.FindName('comboBox1')
$Exit=$Form.FindName('button1')
$var=“测试”
$Fonction.Items.add($var)
$Exit.add_单击({$Form.close()})
$Form.ShowDialog()| Out Null
它对我有效(当我单击组合框的下拉按钮时,我可以看到test
),但请注意,在粘贴的示例中,[xml]$XAML=@
后有一个反勾号,这应该是一个单引号:”
。它有效!非常感谢你!!它对我有效(当我单击组合框的下拉按钮时,我可以看到test
),但请注意,在粘贴的示例中,[xml]$XAML=@
后面有一个反勾号,这应该是一个单引号:”
。它有效!非常感谢你!!