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

  • Home
  • SEARCH
  • 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 8532589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:44:59+00:00 2026-06-11T09:44:59+00:00

I’m building a Windows 8 Store app and I’m having trouble with a CollectionViewSource

  • 0

I’m building a Windows 8 Store app and I’m having trouble with a CollectionViewSource claiming that the collection it is returning has zero items when async is involved.

In my ViewModel I have the following code (note some stuff is missing to make this a bit more simple to explain)

public MainViewModel(IFileRepository fileRepository)
{
   items = new CollectionViewSource();
   _fileRepository = fileRepository;
   this.Construct();
   items.Source = new ObservableCollection<FileViewModel>(Files);
}

private async void Construct()
{
   Files = new ObservableCollection<FileViewModel>();
   IList _files = await _fileRepository.GetFiles();
   foreach (File file in _files)
   {
      Files.Add(new FileViewModel(file));
   }
}

private CollectionViewSource items;
public ICollectionView Items
{
    get
    {
        return items.View;
    }
}

And then in the XAML I’m binding a GridView’s ItemsSource to Items and I have all the relevant DataTemplates in place to display the data.

My issue is that, because of the async fetch of the files, my Items collection returns empty and the View presents no data.

If I remove the async call and create a mock collection of File objects inline, the code works as expected.

Can anybody suggest a way around this? In WPF I would attempt to create a Boolean isBusy property for when the collection is loading, but that feels like a wrong thing to do with this new async stuff.

Any pointers would be great!

Kris

  • 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-11T09:45:00+00:00Added an answer on June 11, 2026 at 9:45 am

    As it stands, when you create the ObservableCollection for the Source, Files is empty since you started Construct, but didn’t (a)wait for it to finish.

    I would avoid the second ‘wrapper’ ObservableCollection and set Source = Files, so when the Construct code writes to Files, it’ll be observed by the CollectionViewSource (which is likely your actual intent)

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

Sidebar

Related Questions

I'm building a Windows Service app that has configuration data stored in App.Config. However,
I'm building a windows application that search items from sharepoint document libraries, using the
I am building a C# windows form app that pings multiple computers by name,
I'm building a Windows 8 Metro app (aka Modern UI Style or Windows Store
I'm building a Windows Phone application and my client has given me a list
I'm building a Windows Phone 7 app, and I need a reference to my
I'm building a Windows Form that includes a combo box control, and I wanted
I'm exploring package building on Windows 7 but have been running into trouble after
I'm building a windows phone 7 application using silverlight 4. I store my data
I'm a little confused about building an app for the app store and for

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.