C# 如何将xml标记中的数据绑定到xamdatagrid或wpf中的datagrid中的组合框? xml文件。

C# 如何将xml标记中的数据绑定到xamdatagrid或wpf中的datagrid中的组合框? xml文件。,c#,wpf,xaml,combobox,xamdatagrid,C#,Wpf,Xaml,Combobox,Xamdatagrid,我想知道如何从xml文件中检索“product”中的值,然后如何绑定到xamdatagrid中的组合框?xml格式不正确。下面将帮助您从XML中获取产品列表,然后您可以将其绑定到所需的控件(在您的示例中为combobox <igDP:UnboundField Name="Product" Label="Product Name"> <igDP:UnboundField.Settings>

我想知道如何从xml文件中检索“product”中的值,然后如何绑定到xamdatagrid中的组合框?

xml格式不正确。下面将帮助您从XML中获取产品列表,然后您可以将其绑定到所需的控件(在您的示例中为
combobox

                    <igDP:UnboundField Name="Product" Label="Product Name">
                        <igDP:UnboundField.Settings>
                            <igDP:FieldSettings EditorType="{x:Type igEditors:XamComboEditor}" AllowEdit="True">
                                <igDP:FieldSettings.EditorStyle>
                                    <Style TargetType="{x:Type igEditors:XamComboEditor}">
                                        <EventSetter Event="Loaded" Handler="Combo_Loaded"/>
                                        <Setter Property="ItemsSource" Value="{Binding Items}" />

                                    </Style>
                                </igDP:FieldSettings.EditorStyle>
                            </igDP:FieldSettings>
                        </igDP:UnboundField.Settings>
                    </igDP:UnboundField>
                </igDP:FieldLayout.Fields>
            </igDP:FieldLayout>
        </igDP:XamDataGrid.FieldLayouts>
    </igDP:XamDataGrid>
</Grid>
string productXML = @"<Products>
                        <ProductTemplate>
                          <ProductID> 1</ProductID>
                          <ProductLot>11</ProductLot>
                          <Product>product1</Product>
                          <Product>product1</Product>
                        </ProductTemplate>
                     </Products>";

XDocument xdoc = XDocument.Parse(productXML);
//This will give you the list of Products which you can bind with your control
var listOfProducts = xdoc.Descendants("Products").Elements("ProductTemplate").Descendants().Where(x => x.Name == "Product").Select(x => x.Value).ToList();
string productXML=@”
1.
11
产品1
产品1
";
XDocument xdoc=XDocument.Parse(productXML);
//这将为您提供可以与控件绑定的产品列表
var listOfProducts=xdoc.substands(“产品”).Elements(“产品模板”).substands()。其中(x=>x.Name==“产品”)。选择(x=>x.Value)。ToList();

XML格式不正确。下面将帮助您从XML中获取产品列表,然后您可以将其绑定到所需的控件(在您的示例中为
combobox

                    <igDP:UnboundField Name="Product" Label="Product Name">
                        <igDP:UnboundField.Settings>
                            <igDP:FieldSettings EditorType="{x:Type igEditors:XamComboEditor}" AllowEdit="True">
                                <igDP:FieldSettings.EditorStyle>
                                    <Style TargetType="{x:Type igEditors:XamComboEditor}">
                                        <EventSetter Event="Loaded" Handler="Combo_Loaded"/>
                                        <Setter Property="ItemsSource" Value="{Binding Items}" />

                                    </Style>
                                </igDP:FieldSettings.EditorStyle>
                            </igDP:FieldSettings>
                        </igDP:UnboundField.Settings>
                    </igDP:UnboundField>
                </igDP:FieldLayout.Fields>
            </igDP:FieldLayout>
        </igDP:XamDataGrid.FieldLayouts>
    </igDP:XamDataGrid>
</Grid>
string productXML = @"<Products>
                        <ProductTemplate>
                          <ProductID> 1</ProductID>
                          <ProductLot>11</ProductLot>
                          <Product>product1</Product>
                          <Product>product1</Product>
                        </ProductTemplate>
                     </Products>";

XDocument xdoc = XDocument.Parse(productXML);
//This will give you the list of Products which you can bind with your control
var listOfProducts = xdoc.Descendants("Products").Elements("ProductTemplate").Descendants().Where(x => x.Name == "Product").Select(x => x.Value).ToList();
string productXML=@”
1.
11
产品1
产品1
";
XDocument xdoc=XDocument.Parse(productXML);
//这将为您提供可以与控件绑定的产品列表
var listOfProducts=xdoc.substands(“产品”).Elements(“产品模板”).substands()。其中(x=>x.Name==“产品”)。选择(x=>x.Value)。ToList();

感谢您的回复和时间Richa Garg。解决方案在我的代码中不起作用。我从“product.xml”文件中获取输入。所以我尝试使用XDocument xdoc=XDocument.Load(“C:/Products/Product.xml”)——它不起作用。我也试过使用你的代码片段。不走运。未在xamdatagrid的combobox中填充数据。我不确定我的binding语句是否正确。您可以尝试将一个组合框绑定到datagrid之外,以检查绑定中是否有问题。当我的代码在我的机器上运行时,mbobox正在xamdatagrid中填充,但是列表是空的。没办法解决Richa Garg你的解决方案现在很好。我可以在我的代码中找到它。感谢您宝贵的时间和帮助。感谢您的回复和时间Richa Garg。解决方案在我的代码中不起作用。我从“product.xml”文件中获取输入。所以我尝试使用XDocument xdoc=XDocument.Load(“C:/Products/Product.xml”)——它不起作用。我也试过使用你的代码片段。不走运。未在xamdatagrid的combobox中填充数据。我不确定我的binding语句是否正确。您可以尝试将一个组合框绑定到datagrid之外,以检查绑定中是否有问题。当我的代码在我的机器上运行时,mbobox正在xamdatagrid中填充,但是列表是空的。没办法解决Richa Garg你的解决方案现在很好。我可以在我的代码中找到它。谢谢你宝贵的时间和帮助。