我的观点中哪些不对? Xamdatagrid不显示组合框数据

时间:2016-10-02 16:40:35

标签: wpf data-binding datagrid infragistics xamdatagrid

我想在MVVM样式的xamDataGrid中的products.xml中显示数据。绑定无法正常工作。必须将Product节点中的值添加到xamDatagrid中的组合框字段。组合框未显示任何数据。有人可以教我如何解决这个问题吗?

Product.xml

<?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>

products.cs [viewModel Class]

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;
            }
        }
    }
}

view.xml用

<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>

View.xaml.cs

public partial class View : Window
        {
            public View()
            {
                InitializeComponent();

                WaferGen wg = new WaferGen();
                this.DataContext = wg;
                wg.display();
            }
        }

1 个答案:

答案 0 :(得分:1)

最后,我能够找到解决方案。我在这里张贴它,以便它可以帮助像我这样的人。

function read($sessID) { 
    // fetch session-data 
    $res = mysql_query("SELECT session_data AS d FROM ws_sessions 
                        WHERE session_id = '$sessID' 
                        AND session_expires > ".time(),$this->dbHandle); 
    // return data or an empty string at failure 
    if($row = mysql_fetch_assoc($res)) 
        return $row['d']; 
    return ""; 
}