WPF Controls lookupedit,我无法填写lookupedit

时间:2018-01-12 12:55:02

标签: c# wpf devexpress gridlookupedit

的.xaml

 <Grid>
        <dxg:LookUpEdit Name="lookUpEdit1"
                        DisplayMember="ProductName"
                        ValueMember="ID"
                        AutoPopulateColumns="False"
                        AutoComplete="True"
                        IncrementalFiltering="True"
                        ImmediatePopup="True"
                        IsPopupAutoWidth="False"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Top"
                        Width="200" Margin="10">
            <dxg:LookUpEdit.PopupContentTemplate>
                <ControlTemplate>
                    <dxg:GridControl Name="PART_GridControl">
                        <dxg:GridControl.Columns>
                            <dxg:GridColumn FieldName="ProductName"/>
                            <dxg:GridColumn FieldName="UnitPrice"/>
                            <dxg:GridColumn FieldName="Quantity"/>
                        </dxg:GridControl.Columns>
                        <dxg:GridControl.View>
                            <dxg:TableView AutoWidth="True"/>
                        </dxg:GridControl.View>
                    </dxg:GridControl>
                </ControlTemplate>
            </dxg:LookUpEdit.PopupContentTemplate>
        </dxg:LookUpEdit>
    </Grid>

MainWindow_Loaded {

lookUpEdit1.ItemsSource =新产品(&#34; ad&#34;,&#34; 1&#34;,5,100);

}

class Product
    {
        public string ProductName { get; set; }
        public string ID { get; set; }
        public double UnitPrice { get; set; }
        public int Quantity { get; set; }

        public Product(string productName, string id, double unitPrice, int quantity)
        {
            ProductName = productName;
            ID = id;
            UnitPrice = unitPrice;
            Quantity = quantity;
        }
    }

enter image description here

如您所见。 我看不到你的意思。我等着你的帮忙..

1 个答案:

答案 0 :(得分:0)

ItemsSource属性期望任何派生自IEnumerable的对象,因为您设置单个Product,底层GridControl不知道如何处理它。

要修复,只需将ItemsSource设置为Product的列表。

More info here