Dear all,
I have a list box which is bind to a List of Product Categories with a maximum of 4 categories. Then when my user select one category I need to collect all product within that category. Then I am using the same list box and change the item source with new collected data ( this to avoid having an other items control to handle a new list querry, may be bad idea!)
For that on selected category item, I run following code from a ViewModel
private void ProcessSelectCategoryCommand(ListBox Container,RootCategoryViewModel cat) { // we select a category and need to get list of product based on that category SelectedProductCategory = cat; Messenger.Default.Send<Message.OpenProductList>(new Message.OpenProductList(this,Container,true)); //call asynchronously the product summary information from slelected category of product Task.Factory.StartNew(() => { GetProductSummaryData(SelectedProductCategory, ViewModelLocator.MainViewModelStatic.StoreInfoViewModel.StoreId); }).ContinueWith(task => { if (task.IsFaulted) { Exception ex = task.Exception; log.Debug("Task Faulted <ProcessSelectCategoryCommand>", ex.InnerException); } else { ProductListReady = true; IsCategoryListVisible = false; Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { if (ProductSummaryItems != null) { //ICollectionView view = CollectionViewSource.GetDefaultView(ProductSummaryItems); //view.GroupDescriptions.Add(new PropertyGroupDescription("SubCatgoryName")); //view.SortDescriptions.Add(new SortDescription("SubCatgoryName", ListSortDirection.Ascending)); Container.ItemsSource = ProductSummaryItems; } else Container.ItemsSource = null; })); } }); }
What is weird in that, in order to not show to user the change of data for the same list box, I hide the list box then change the itemSource and then show the list box. I am doing this in order to avoid seeing to user sundenly change of data which is not so user friendly in user experience.
Do you see a better smoother approach for doing this ?
Does the fact of handling single Listbox in that case is suitable or better to go with separate controls?
thnks for advise
regards