Exemplo 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);
            }
        }
Exemplo n.º 2
0
        private static void ShowKeys(List <FrameworkElement> elements)
        {
            CloseQuickAccessKeys();
            popups = new List <Popup>();
            foreach (var e in elements)
            {
                double yOffset = KeyTip.GetYOffset(e);
                double xOffset = KeyTip.GetXOffset(e);
                if (xOffset < 0.0)
                {
                    xOffset = e.ActualWidth + xOffset;
                }
                if (yOffset < 0.0)
                {
                    yOffset = e.ActualHeight + yOffset;
                }

                if (double.IsNaN(yOffset))
                {
                    yOffset = e.ActualHeight - 16;
                }
                if (double.IsNaN(xOffset))
                {
                    xOffset = 12;
                }
                string key   = KeyTip.GetKey(e);
                Popup  popup = new Popup();
                popup.AllowsTransparency = true;
                popup.Child = new KeyTip()
                {
                    Text = key
                };
                popup.PlacementTarget  = e;
                popup.Placement        = PlacementMode.Relative;
                popup.HorizontalOffset = xOffset;
                popup.VerticalOffset   = yOffset;
                popup.StaysOpen        = true;
                popups.Add(popup);
                popup.IsOpen = true;
            }
        }
Exemplo n.º 3
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);
                    }
                }
            }
        }