Create A WPF ObservableCollection From A SubSonic 2.2 Collection

梦想与她 提交于 2019-12-24 12:23:50

问题


If I have a DAL created by SubSonic 2.2, how do I convert the Collections created by it to WPF ObservableCollections in code (pref.VB.NET) to be consumed by WPF?


回答1:


Sorry !VB:

[Test]
public void Exec_Testing()
{
    ProductCollection products =
        DB.Select().From("Products")
            .Where("categoryID").IsEqualTo(5)
            .And("productid").IsGreaterThan(50)
            .ExecuteAsCollection<ProductCollection>();

    Assert.IsTrue(products.Count == 77);

    ObservableCollection<Product> obsProducts = new ObservableCollection<Product>(products);
}



回答2:


You would have to manually add this to your DAL classes, but it's not too hard. In the top of each data access layer class, add "Implements INotifyPropertyChanged" and then in each property, add the code in the "set" like you see below.

Private _Book As String
Public Property Book() As String
    Get
        Return _Book
    End Get
    Set(ByVal value As String)
        If Not _Book = value Then
            _Book = value
            ' Raise the property changed event.
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("Book"))
        End If
    End Set
End Property 

Public Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged


来源:https://stackoverflow.com/questions/878199/create-a-wpf-observablecollection-from-a-subsonic-2-2-collection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!