Exemplo n.º 1
0
        /// <summary>
        /// Updates the Selector control's <see cref="ItemsControl.ItemsSource"/> to include the
        /// <see cref="NullItem"/> along with the objects in <see cref="ItemsSource"/>.
        /// </summary>
        protected void Adapt()
        {
            //if (CollectionView != null)
            //{
            //    CollectionView.CurrentChanged -= CollectionView_CurrentChanged;
            //    CollectionView = null;
            //}

            if (Selector != null)
            {
                //if (ItemsSource is System.Collections.Specialized.INotifyCollectionChanged)
                //{
                //    var col = ItemsSource as System.Collections.Specialized.INotifyCollectionChanged;
                //    col.CollectionChanged -= ItemsSource_CollectionChanged;
                //    col.CollectionChanged += ItemsSource_CollectionChanged;
                //}

                CompositeCollection comp = new CompositeCollection();
                if (ItemsSource != null)
                {
                    comp.Add(new CollectionContainer {
                        Collection = ItemsSource
                    });
                }

                //comp.Add(new CollectionContainer { Collection = new string[] { "(None)" } });
                if (NullItems != null)
                {
                    foreach (var item in NullItems)
                    {
                        if (IsAddingNullItemsFirst)
                        {
                            comp.Insert(0, item);
                        }
                        else
                        {
                            comp.Add(item);
                        }
                    }
                }

                //CollectionView = CollectionViewSource.GetDefaultView(comp);
                //if (CollectionView != null) CollectionView.CurrentChanged += CollectionView_CurrentChanged;

                Selector.ItemsSource = comp;
            }
        }