[英]How to display XML data in XAML listbox programmatically?
I have an XML file, each element has name of a product and it's price. 我有一个XML文件,每个元素都有一个产品名称和价格。
I have a XAML file with a listbox. 我有一个带有列表框的XAML文件。
How do I display all the items in the XML file in the listbox programmatically in C#? 如何在C#中以编程方式在列表框中显示XML文件中的所有项目? Thanks. 谢谢。
Here is my XML file with 3 sample products: 这是带有3个示例产品的XML文件:
<?xml version="1.0" encoding="UTF-8"?>
<dataroot xmlns:od="urn:schemas-microsoft-com:officedata" generated="2011-09-20T15:04:12">
<Product>
<Name>Red Chair</Name>
<Price>29.5</Price>
</Product>
<Product>
<Name>Blue Chair</Name>
<Price>27</Price>
</Product>
<Product>
<Name>Round Table</Name>
<Price>31</Price>
</Product>
</dataroot>
Here's my XAML: 这是我的XAML:
<Window x:Class="DockPanel.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Inventory" Height="350" Width="525">
<DockPanel>
<ListBox Name="listBox1" Margin="10" >
</ListBox>
</DockPanel>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.