我想在MVVM样式的xamDataGrid中的products.xml中显示数据。绑定无法正常工作。必须将Product节点中的值添加到xamDatagrid中的组合框字段。
<?xml version="1.0" encoding="utf-8" ?>
<WG>
<WGT>
<TName>tanme1</TName>
<Fname>fname1</Fname>
<Product>Product1</Product>
<Product>Product2 </Product>
</WGT>
<WGT>
<TName>tanme2</TName>
<Fname>fname2</Fname>
</WGT>
<WGT>
<TName>tanme1</TName>
<Fname>fname1</Fname>
<Product>Product1</Product>
<Product>Product2 </Product>
<Product>Product3 </Product>
<Product>Product4 </Product>
</WGT>
<WGT>
<TName>tanme5</TName>
<Fname>fname5</Fname>
</WGT>
<WGT>
<TName>tanme1</TName>
<Fname>fname1</Fname>
<Product>Product1</Product>
<Product>Product2 </Product>
<Product>Product3 </Product>
<Product>Product4 </Product>
<Product>Product5 </Product>
<Product>Product6 </Product>
</WGT>
</WG>
namespace XmlTest.ViewModel
{
public partial class WG : ViewBase
{
private WGWGT[] itemsField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("WGT", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public WGWGT[] Items
{
get
{
return this.itemsField;
}
set
{
this.itemsField = value;
}
}
public void display()
{
XmlSerializer deserializer = new XmlSerializer(typeof(WG));
TextReader reader = new StreamReader(@"C:\xlf\products.xml");
object obj = deserializer.Deserialize(reader);
WG XmlData = (WG)obj;
itemsField = XmlData.Items;
}
}
public partial class WGWGT : ViewBase
{
private string tNameField;
private string fnameField;
private WGWGTProduct[] productField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string TName
{
get
{
return this.tNameField;
}
set
{
this.tNameField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string Fname
{
get
{
return this.fnameField;
}
set
{
this.fnameField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Product", Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = true)]
public WGWGTProduct[] Product
{
get
{
return this.productField;
}
set
{
this.productField = value;
}
}
}
public partial class WGWGTProduct : ViewBase
{
private string valueField;
/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
public string Value
{
get
{
return this.valueField;
}
set
{
this.valueField = value;
}
}
}
}
<Grid>
<igDP:XamDataGrid x:Name="dataGridView1" DataSource="{Binding Items}"
HorizontalAlignment="Left" Height="800" Margin="10,56,0,0" VerticalAlignment="Top" Width="800">
<igDP:XamDataGrid.FieldLayoutSettings >
<igDP:FieldLayoutSettings AutoGenerateFields="False"/>
</igDP:XamDataGrid.FieldLayoutSettings>
<igDP:XamDataGrid.FieldLayouts >
<igDP:FieldLayout>
<igDP:FieldLayout.Fields >
<igDP:Field Label="Template Name" Name="TName" />
<igDP:Field Label="File Name" Name="FName"/>
<igDP:UnboundField Label="Product Name" >
<igDP:UnboundField.Settings>
<igDP:FieldSettings EditorType="{x:Type igEditors:XamComboEditor}" AllowEdit="True">
<igDP:FieldSettings.EditorStyle>
<Style TargetType="{x:Type igEditors:XamComboEditor}">
<Setter Property="ItemsSource" Value="{Binding Product}" />
<Setter Property="DisplayMemberPath" Value="Value" />
</Style>
</igDP:FieldSettings.EditorStyle>
</igDP:FieldSettings>
</igDP:UnboundField.Settings>
</igDP:UnboundField>
</igDP:FieldLayout.Fields>
</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>
</Grid>
public partial class View : Window
{
public View()
{
InitializeComponent();
WaferGen wg = new WaferGen();
this.DataContext = wg;
wg.display();
}
}