Microsoft.Samples.KMoore.WPFSamples.Zap.ZapScroller.resetCommands C# (CSharp) Method

resetCommands() private method

private resetCommands ( ) : void
return void
        private void resetCommands()
        {
            int parentItemsCount = this.ItemCount;

            if (parentItemsCount != _commands.Count)
            {
                if (parentItemsCount > _commands.Count)
                {
                    for (int i = _commands.Count; i < parentItemsCount; i++)
                    {
                        _commands.Add(new ZapCommandItem(this, i));
                    }
                }
                else
                {
                    Debug.Assert(parentItemsCount < _commands.Count);
                    int delta = _commands.Count - parentItemsCount;
                    for (int i = 0; i < delta; i++)
                    {
                        _commands.RemoveAt(_commands.Count - 1);
                    }
                }
            }

            Debug.Assert(ParentItems.Count == _commands.Count);

            //KMoore - 2007-01-08
            //BUGBUG: no clue why I can't use binding here. For somereason item changes are not sent through
            //from the collectionView. Need to talk to smart people about this
            for (int i = 0; i < parentItemsCount; i++)
            {
                _commands[i].Content = ParentItems[i];
            }

            #if DEBUG
            for (int i = 0; i < _commands.Count; i++)
            {
                Debug.Assert(((ZapCommandItem)_commands[i]).Index == i);
            }
            #endif
        }