C# 将项目添加到画布内WPF中的combobox
你好 我想将特定项目添加到组合框中,但遇到错误 代码:C# 将项目添加到画布内WPF中的combobox,c#,xml,wpf,xaml,combobox,C#,Xml,Wpf,Xaml,Combobox,你好 我想将特定项目添加到组合框中,但遇到错误 代码: 添加类型-AssemblyName PresentationFramework [xml]$Form=@” "@ $NR=(新对象System.Xml.XmlNodeReader$Form) $Win=[Windows.Markup.XamlReader]::加载($NR) $Win.Showdialog() 如您所见,我尝试添加项,但错误如下 Cannot convert value "<Window xmlns=...</
添加类型-AssemblyName PresentationFramework
[xml]$Form=@”
"@
$NR=(新对象System.Xml.XmlNodeReader$Form)
$Win=[Windows.Markup.XamlReader]::加载($NR)
$Win.Showdialog()
如您所见,我尝试添加项,但错误如下
Cannot convert value "<Window xmlns=...</Window>" to type "System.Xml.XmlDocument".
Error: "The 'Canvas' start tag on line 4 position 6 does not match the end tag of
'ComboBox'. Line 12, position 11."
At H:\Scripts\Form_Main_XAML.ps1:3 char:1
+ [xml]$Form = @"
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : MetadataError: (:) [], ArgumentTransformationMetadataException
+ FullyQualifiedErrorId : RuntimeException
无法转换表示以下内容的块的值“:
<ComboBox Name="ComboBox_Location" HorizontalAlignment="Left" Margin="170,56,0,0" VerticalAlignment="Top" Width="160"/>
<ComboBoxItem Content="X"/>
<ComboBoxItem Content="Y"/>
<ComboBoxItem Content="Z"/>
</ComboBox>
第一行以/>
结尾,在该行中,结束标记指定组合框定义的结尾。相反,您希望以
结尾,并让相应的
行关闭块。您的XAML组合框有一个结束标记,但它不应该:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Title="Printer GUI" Height="465" Width="375">
<Canvas Background="White">
<Label Name="label_username" Content="Username" HorizontalAlignment="Left" Margin="30,30,0,0" VerticalAlignment="Top"/>
<Label Name="label_Location" Content="Select Location" HorizontalAlignment="Left" Margin="170,30,0,0" VerticalAlignment="Top"/>
<TextBox Name="textbox_username" HorizontalAlignment="Left" Height="23" Margin="30,56,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<ComboBox Name="ComboBox_Location" HorizontalAlignment="Left" Margin="170,56,0,0" VerticalAlignment="Top" Width="160">
<ComboBoxItem Content="X"/>
<ComboBoxItem Content="Y"/>
<ComboBoxItem Content="Z"/>
</ComboBox>
<Label Name="label_printer" Content="Please select printer from list" HorizontalAlignment="Left" Margin="30,105,0,0" VerticalAlignment="Top"/>
<ComboBox Name="ComboBox_Printer" HorizontalAlignment="Left" Margin="30,131,0,0" VerticalAlignment="Top" Width="300"/>
<CheckBox Name="CheckBox" Content="Check here if you want to add this printer 
	to your permanent list" HorizontalAlignment="Left" Margin="56,185,0,0" VerticalAlignment="Top" Height="39" Width="245"/>
<Button Name="Button_Add" Content="Add Printer" Margin="140,244,140,150" Width="75" Height="25" VerticalAlignment="Center" ClickMode="Release"/>
<Button Name="Button_XPS" Content="Printer Defaults issue
 in Practice Partner" Margin="90,285,90,102" Width="175" Height="40" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" ClickMode="Release" VerticalAlignment="Center"/>
<Button Name="Button_Service" Content="Service call for Printer" Margin="113,343,110,51" Width="130" Height="25" VerticalAlignment="Center" ClickMode="Release"/>
<Button Name="Button_Cancel" Content="Cancel" Margin="140,384,140,10" Width="75" Height="25" VerticalAlignment="Center" ClickMode="Release"/>
</Canvas>
</Window>
谢谢@Chris。我应该知道这是一个简单的修复。我需要观察我的开始和结束。谢谢你的解释!@Megamidget3一点问题都没有!这是我第一次在中学习XAML时的一个小烦恼,而不是本能地键入/
来完成标记,因为它会自动填充
。我的建议n就是养成创建控件的习惯,
,这样它会自动为您填充
,并将其隔开,从而为您提供一个视觉提示,让您将子项放入其中。
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Title="Printer GUI" Height="465" Width="375">
<Canvas Background="White">
<Label Name="label_username" Content="Username" HorizontalAlignment="Left" Margin="30,30,0,0" VerticalAlignment="Top"/>
<Label Name="label_Location" Content="Select Location" HorizontalAlignment="Left" Margin="170,30,0,0" VerticalAlignment="Top"/>
<TextBox Name="textbox_username" HorizontalAlignment="Left" Height="23" Margin="30,56,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<ComboBox Name="ComboBox_Location" HorizontalAlignment="Left" Margin="170,56,0,0" VerticalAlignment="Top" Width="160">
<ComboBoxItem Content="X"/>
<ComboBoxItem Content="Y"/>
<ComboBoxItem Content="Z"/>
</ComboBox>
<Label Name="label_printer" Content="Please select printer from list" HorizontalAlignment="Left" Margin="30,105,0,0" VerticalAlignment="Top"/>
<ComboBox Name="ComboBox_Printer" HorizontalAlignment="Left" Margin="30,131,0,0" VerticalAlignment="Top" Width="300"/>
<CheckBox Name="CheckBox" Content="Check here if you want to add this printer 
	to your permanent list" HorizontalAlignment="Left" Margin="56,185,0,0" VerticalAlignment="Top" Height="39" Width="245"/>
<Button Name="Button_Add" Content="Add Printer" Margin="140,244,140,150" Width="75" Height="25" VerticalAlignment="Center" ClickMode="Release"/>
<Button Name="Button_XPS" Content="Printer Defaults issue
 in Practice Partner" Margin="90,285,90,102" Width="175" Height="40" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" ClickMode="Release" VerticalAlignment="Center"/>
<Button Name="Button_Service" Content="Service call for Printer" Margin="113,343,110,51" Width="130" Height="25" VerticalAlignment="Center" ClickMode="Release"/>
<Button Name="Button_Cancel" Content="Cancel" Margin="140,384,140,10" Width="75" Height="25" VerticalAlignment="Center" ClickMode="Release"/>
</Canvas>
</Window>