Beispiel #1
0
        /// <summary>
        /// Raises the <see cref="UIElement.KeyDown"/> event.
        /// </summary>
        /// <param name="e">
        /// The <see cref="KeyEventArgs"/> instance containing the event data.
        /// </param>
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            base.OnKeyDown(e);

            if (e.Handled)
            {
                return;
            }

            // TODO: Consider FlowDirection for Left/Right.
            switch (e.Key)
            {
            case Key.Left:
            case Key.Subtract:
                if (CanExpand && IsEnabled && IsExpanded)
                {
                    e.Handled  = true;
                    IsExpanded = false;
                }
                break;

            case Key.Add:
            case Key.Right:
                if (CanExpand && IsEnabled && !IsExpanded)
                {
                    e.Handled  = true;
                    IsExpanded = true;
                }
                break;
            }

            if (!e.Handled)
            {
                ParentTreeView?.HandleKeyDown(this, e);
            }
        }