CSLA .NET

From Rockford Lhotka's Expert C# 2008 and VB 2008 Business Objects books

Welcome to CSLA .NET Sign in | Join | Help
in Search

Xaml binding to sorted list

Last post 12-09-2008, 12:21 AM by daniel_higgins. 3 replies.
Sort Posts: Previous Next
  •  11-23-2008, 11:22 PM 28531

    Xaml binding to sorted list

    Hi All,

    Does xaml binding to a sorted wpf view work in csla 3.5?

    In c#, I tried:

    ICollectionView view = CollectionViewSource.GetDefaultView(parent.ChildCollection);

    view.SortDescriptions.Add(new SortDescription("Ordinal", ListSortDirection.Ascending));

    And it failed. When I looked at *view* in the debugger, its CanSort property was false.

    Am I barking up the wrong tree here?

  •  12-08-2008, 1:03 PM 28980 in reply to 28531

    Re: Xaml binding to sorted list

    Hi

    In the non-csla samples I've looked at, using the SortDescriptions on a collection and setting the ItemsSource="{Binding ChildCollection}" in Xaml seemed to work pretty well. When I added a new item to the child collection, the new item shows up in the list box.

    In csla, adding a SortDescription to the default collection view (as per wpf examples I've read), does not appear to work.

    So I used the csla linq features:

    listBox.ItemsSource = from c in parent.ChildCollection orderby c.Ordinal select c;

    That gives me a sorted list. When I add a new item to the collection (parent.ChildCollection.AddNew()), it does not appear in the list box. I thought the linq equipment in csla returned a "hot list" that was tied to the underlying collection.

    So, I suppose I have two questions:

    1. Does the wpf CollectionView and SortDescriptions stuff work on csla collections?

    2. If I cannot use the CollectionView/SortDescriptions stuff, and I instead use linq on clsa, do I need to un-and-re-bind to linq query result? Perhaps I am using the wrong linq expression?

    Thank you

  •  12-09-2008, 12:08 AM 28990 in reply to 28980

    Re: Xaml binding to sorted list

    I don't think the CollectionView stuff works with CSLA.  My guess is because CSLA collections don't allow sorting.  There is a class called SortedBindingList<T> that is used to provide this functionality.  It is described in detail in the 2005 business objects book.

  •  12-09-2008, 12:21 AM 28993 in reply to 28990

    Re: Xaml binding to sorted list

    Thanks for the reply Jeff.

    I was able to get the effect I wanted by using

    ListCollectionView myView = new ListCollectionView(parent.ChildCollection);

    then applying the SortDescriptions to this new ListCollectionView. I guess the DefaultCollectionView is not sortable.

    It likely has something to do with the differences between BindingList and ObservableCollection, but I had to call myView.Refresh() every time I added a new child to the collection (parent.ChildCollection.AddNew()).

View as RSS news feed in XML

Please contact Magenic for your .NET consulting
and CSLA .NET mentoring needs.
Please consider making a donation to help support the ongoing development of CSLA .NET.

Make donation through PayPal - it's fast, free and secure!
Why donate?
Powered by Community Server, by Telligent Systems