Ejemplo n.º 1
0
        private static bool CheckQuickAccessKey(KeyEventArgs e)
        {
            if (elements == null || elements.Count == 0)
            {
                return(false);
            }
            string c = new KeyConverter().ConvertToInvariantString(e.Key);

            keySequence += c;

            FrameworkElement        match    = null;
            List <FrameworkElement> filtered = new List <FrameworkElement>();

            foreach (FrameworkElement child in elements)
            {
                string key = KeyTip.GetKey(child);
                if (keySequence.Equals(key, StringComparison.InvariantCultureIgnoreCase))
                {
                    match = child;
                    break;
                }
                if (key.StartsWith(keySequence, StringComparison.InvariantCultureIgnoreCase))
                {
                    filtered.Add(child);
                }
            }
            if (match != null)
            {
                keySequence = null;
                //Remove the key tips befor executing, since another window might be opened and thus the key tips would be desturbing:
                HideQuickAccessKeys();
                ExecuteElement(match);
                if (KeyTip.GetStop(match))
                {
                    // ensure the matched element to be measured:
                    match.UpdateLayout();

                    ShowQuickAccessKeys(match);
                }
                else
                {
                    HideQuickAccessKeys();
                }
                return(true);
            }
            if (filtered.Count > 0)
            {
                elements = filtered;
                ShowKeys(elements);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Don't call this directly, it is only used in GatherChildElements.
        /// </summary>
        private static void GatherElements(List <FrameworkElement> elements, FrameworkElement root)
        {
            if (root.Visibility != Visibility.Visible || root.IsEnabled == false)
            {
                return;
            }
            string key = KeyTip.GetKey(root);

            if (key != null)
            {
                elements.Add(root);
            }
            if (key == null || !KeyTip.GetStop(root))
            {
                foreach (var o in LogicalTreeHelper.GetChildren(root))
                {
                    FrameworkElement e = o as FrameworkElement;
                    if (e != null)
                    {
                        GatherElements(elements, e);
                    }
                }
            }
        }