/// <summary>
        /// Provides handling for the KeyDown event.
        /// </summary>
        /// <param name="e">Key event args.</param>
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            if (e.Handled || !IsEnabled || IsLocked)
            {
                return;
            }

            // Some keys (e.g. Left/Right) need to be translated in RightToLeft mode
            Key invariantKey = InteractionHelper.GetLogicalKey(FlowDirection, e.Key);

            bool isSelected = IsSelected;

            switch (ExpandDirection)
            {
            case ExpandDirection.Down:
                if ((isSelected && invariantKey == Key.Up) || (!isSelected && invariantKey == Key.Down))
                {
                    IsSelected = !isSelected;
                }
                break;

            case ExpandDirection.Up:
                if ((isSelected && invariantKey == Key.Down) || (!isSelected && invariantKey == Key.Up))
                {
                    IsSelected = !isSelected;
                }
                break;

            case ExpandDirection.Left:
                if ((isSelected && invariantKey == Key.Right) || (!isSelected && invariantKey == Key.Left))
                {
                    IsSelected = !isSelected;
                }
                break;

            case ExpandDirection.Right:
                if ((isSelected && invariantKey == Key.Left) || (!isSelected && invariantKey == Key.Right))
                {
                    IsSelected = !isSelected;
                }
                break;
            }
        }
        /// <summary>
        /// Initializes a new instance of the AccordionItem class.
        /// </summary>
        public AccordionItem()
        {
            // initialize to no action.
            ScheduledAction = AccordionAction.None;

            DefaultStyleKey = typeof(AccordionItem);
            _interaction = new InteractionHelper(this);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Accordion"/> class.
        /// </summary>
        public Accordion()
        {
            DefaultStyleKey = typeof(Accordion);
            ItemsControlHelper = new ItemsControlHelper(this);

            ObservableCollection<object> items = new ObservableCollection<object>();
            ObservableCollection<int> indices = new ObservableCollection<int>();

            SelectedItems = items;
            SelectedIndices = indices;

            items.CollectionChanged += OnSelectedItemsCollectionChanged;
            indices.CollectionChanged += OnSelectedIndicesCollectionChanged;

            _scheduledActions = new List<AccordionItem>();
            SizeChanged += OnAccordionSizeChanged;
            Interaction = new InteractionHelper(this);
        }