Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8064731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:27:27+00:00 2026-06-05T11:27:27+00:00

I am working on a scheduling program in which items have a scheduled date,

  • 0

I am working on a scheduling program in which items have a scheduled date, but the user can elect to override this for a date they choose. To implement this, my Item object uses two properties: ScheduledDate (DateTime) and ActualDate (DateTime?). Therefore, if the ActualDate property is null, the user has not overridden the schedule for this item.

In one of my views, I need to display these items in a ListBox, sorted by the actual date. The trouble I am having is how to implement a CollectionViewSource with these two properties.

I know it’s not correct, but I need something like this:

<CollectionViewSource x:Key="TransactionsViewSource"
                      Source="{Binding ElementName=ThisControl, 
                                       Path=Items}">
    <CollectionViewSource.SortDescriptions>
        <cm:SortDescription PropertyName="ActualDate ?? ScheduledDate"/>
    </CollectionViewSource.SortDescriptions>
</CollectionViewSource>

(ThisControl is the name of the UserControl that hosts the ListBox.)

If I add a second SortDescriptor (like below), I get a list sorted by ActualDate, then by Scheduled Date, which groups all of the overridden items together. This is not the desired behavior.

<CollectionViewSource x:Key="TransactionsViewSource"
                      Source="{Binding ElementName=ThisControl, 
                                       Path=Items}">
    <CollectionViewSource.SortDescriptions>
        <cm:SortDescription PropertyName="ActualDate"/>
        <cm:SortDescription PropertyName="ScheduledDate"/>
    </CollectionViewSource.SortDescriptions>
</CollectionViewSource>

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T11:27:28+00:00Added an answer on June 5, 2026 at 11:27 am

    I ended up creating a new method in my UserControl class that used LINQ to keep the underlying ObservableCollection sorted. I then called this method whenever an item was edited (actual date overridden) or if a new item was added. Finally, I removed the CollectionViewSource from the XAML and bound the ListBox to the Items property (which I already had as a dependency property). The result looks like this:

    XAML:

    <ListBox ItemsSource="{Binding ElementName=ThisControl,
                                   Path=Items}"/>
    

    C#:

    public static readonly DependencyProperty ItemsProperty =
        DependencyProperty.Register("Items",
                                    typeof(ObservableCollection<MyItem>),
                                    typeof(MyControl),
                                    new UIPropertyMetadata(null));
    
    public ObservableCollection<MyItem> Items
    {
        get { return (ObservableCollection<MyItem>) GetValue(ItemsProperty); }
        set { SetValue(ItemsProperty, value); }
    }
    
    private void SortItems()
    {
        Items = new ObservableCollection<MyItem>(Items.OrderBy(i => i.ActualDate ??
                                                                    i.ScheduledDate));
    }
    

    Then I just use SortItems() anywhere that the items in the collection or the collection itself changes.

    It works perfectly, and I didn’t have to create and manage a new property. I can live with the little bit of overhead that LINQ creates.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this control I am working on for scheduling. I have a list
I have been working on a scheduling website for the past few weeks. I
I have a website which I have been working on creating very rapidly, and
So I've been working on program in which I'm creating a hash table in
We have implemented quartz for scheduling.Every job produced have different key.It was working fine
I'm working on university scheduling problem and using simple genetic algorithm for this. Actually
I am working on an application which needs scheduling (just like the one present
I am using AlarmManager to poll user location periodically which is working fine- Now
Working on joining up two legacy DB systems into new database where I can
I'm working on a scheduling system in Java that sends out reminders based on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.