Had an interesting issue on one of our WPF applications that is using MVVM Lite.

image

This application is a front end to upload and download folder structures to TFS. On my development PC all was working fine i.e. when we upload a new folder structure to the TFS backend the various combo’s on the download tab are also updated. However, on another test system they were not updated.

After a bit of tracing we could see in both cases the RefreshData method was being called OK, and the CollectionViews  recreated and bound without errors.

private void RefreshData()
        {
            this.dataService.GetData(
                (item, error) =>
                {
                    if (error != null)
                    {
                        logger.Error(“MainViewModel: Cannot find dataservice”);
                        return;
                    }

                    this.ServerUrl = item.ServerUrl.ToString();
                    this.TeamProjects = new CollectionView(item.TeamProjects);
                    this.Projects = new CollectionView(item.Projects);
                });

            this.TeamProjects.CurrentChanged += new EventHandler(this.TeamProjects_CurrentChanged);

            this.TeamProjects.MoveCurrentToFirst();
          }

So what was the problem? To me it was not obvious.

It turned out it was that on my development system the TeamProject CollectionView contained 2 items, but on the test system only 1.

This means that even though we had recreated the CollectionView and rebound that data and events the calling of MoveCurrentToFirst (or any other move to for that matter) had no effect as there was no place to move to in a collection of one item. Hence the changed event never got called and this in turn stopped the calling of the methods that repopulated the other combos on the download tab.

The solution was to add the following line at the end of the method, and all was OK

            this.TeamProjects.Refresh();