CodeGo.net> WPF的Datagrid和ObservableCollection-AutoGenerateColumns?

我刚刚制定了将属性(DP)绑定到Datagrid的解决方案.没关系,一切都光滑而柔软.但是当我运行应用程序时,DataGrid只显示空白行!(假设有10条记录,我看到10个空白行而没有列!).该属性是ObservableCollection(Customer).
 这是我的Xaml:

DataGrid Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" x:Name="DGCustomers" AutoGenerateColumns="True"  ItemsSource="{Binding CustomersOC}"/>

 

 我要求您浏览一下我的代码

 Public Class CustomersEditor 
 Dim CustomersCollection As New ObservableCollection(Of Customer)
      Public Class Customer
        Public CustomerID As String
        Public CustomerName As String
        Public ContactPerson As String
        Public Address As String
        Public Area As String
        Public City As String
        Public Pincode As String
        Public ContactNumber As String
        Public OnePercentDiscount As Boolean
        Public Sub New(ByVal Cid As String, ByVal Cname As String, ByVal Cperson As String, ByVal Addr As String, ByVal Area1 As String, ByVal Cty As String, ByVal PCode As String, ByVal CNo As String, ByVal OPD As Boolean)
            CustomerID = Cid
            CustomerName = Cname
            ContactPerson = Cperson
            Address = Addr
            Area = Area1
            City = Cty
            Pincode = PCode
            ContactNumber = CNo
            OnePercentDiscount = OPD

        End Sub

    End Class
 Public Shared CustomersColl As DependencyProperty = DependencyProperty.Register("CustomersOC", GetType(ObservableCollection(Of Customer)), GetType(CustomersEditor))
    Public Property CustomersOC As ObservableCollection(Of Customer)
        Get
            Return GetValue(CustomersColl)

        End Get
        Set(ByVal value As ObservableCollection(Of Customer))
            SetValue(CustomersColl, value)

        End Set
    End Property
      Public Sub New()
        InitializeComponent()
      'I have added records to CustomersCollection with Access Database Reader.such as CustomersCollection.Add(new Customer(....))
       SetValue(CustomersColl, CustomersCollection)
       DGCustomers.DataContext = Me


    End Sub
End Class 

有什么解决方案可以使我查看具有九列和适当数据的DataGrid?[AutoGenerateColumns失败!但是,我从数据库中获取数据的代码是完善,完善和有效的.]
 对于C#用户,我拥有converter.telerik.com

解决方法:

您的课程应该包含属性,而不是变量. DataGrid将仅查找公共属性,而不是公共变量.

参见herehere

上一篇:android 长度单位 dp dip sp px pt


下一篇:如何将仅XAML资源放置在WPF应用程序要使用的DLL(参考)文件中?