Exemplo n.º 1
0
        private static void UpdateAttachedAdorner(UIElement element)
        {
            var layer = AdornerLayer.GetAdornerLayer(element);

            if (layer == null)
            {
                var fe = element as FrameworkElement;

                if (fe != null && !fe.IsLoaded)
                {
                    RoutedEventHandler handler = null;

                    handler = (s, e) =>
                    {
                        fe.Loaded -= handler;
                        UpdateAttachedAdorner(fe);
                    };

                    // This element is not loaded yet.  Check again when it is
                    fe.Loaded += handler;
                }
                else
                {
                    Debug.WriteLine("No adorner layer!  Element is not a framework element, or already loaded!  Hands thrown up!");
                }
            }
            else
            {
                bool   isVisible = GetIsAdornerVisible(element);
                Key    key;
                string mode;
                Point? offset = GetOffset(element);
                HorizontalAlignment?horizontalAlignment = GetHorizontalAlignment(element);
                VerticalAlignment?  verticalAlignment   = GetVerticalAlignment(element);
                ShortcutAdorner     adorner             = GetShortcutAdorner(element);

                if (!GetShortcutKeyAndMode(element, out key, out mode))
                {
                    if (adorner != null)
                    {
                        layer.Remove(adorner);
                        SetShortcutAdorner(element, null);
                        adorner = null;
                    }
                }
                else
                {
                    if (adorner == null)
                    {
                        if (isVisible)
                        {
                            adorner = new ShortcutAdorner(element);
                            layer.Add(adorner);
                            SetShortcutAdorner(element, adorner);
                        }
                    }
                    else
                    {
                        if (!isVisible)
                        {
                            layer.Remove(adorner);
                            SetShortcutAdorner(element, null);
                            adorner = null;
                        }
                    }

                    if (adorner != null)
                    {
                        string keyText = key.ToString();

                        if (key >= Key.D0 && key <= Key.D9)
                        {
                            keyText = keyText.Substring(1);
                        }
                        adorner.SetShortcutKey(keyText);
                        adorner.SetPosition(offset, horizontalAlignment, verticalAlignment);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private static void UpdateAttachedAdorner(UIElement element)
        {
            var layer = AdornerLayer.GetAdornerLayer(element);

            if (layer == null)
            {
                var fe = element as FrameworkElement;

                if (fe != null && !fe.IsLoaded)
                {
                    RoutedEventHandler handler = null;

                    handler = (s, e) =>
                    {
                        fe.Loaded -= handler;
                        UpdateAttachedAdorner(fe);
                    };

                    // This element is not loaded yet.  Check again when it is
                    fe.Loaded += handler;
                }
                else
                {
                    Debug.WriteLine("No adorner layer!  Element is not a framework element, or already loaded!  Hands thrown up!");
                }
            }
            else
            {
                bool isVisible = GetIsAdornerVisible(element);
                Key key;
                string mode;
                Point? offset = GetOffset(element);
                HorizontalAlignment? horizontalAlignment = GetHorizontalAlignment(element);
                VerticalAlignment? verticalAlignment = GetVerticalAlignment(element);
                ShortcutAdorner adorner = GetShortcutAdorner(element);

                if (!GetShortcutKeyAndMode(element, out key, out mode))
                {
                    if (adorner != null)
                    {
                        layer.Remove(adorner);
                        SetShortcutAdorner(element, null);
                        adorner = null;
                    }
                }
                else
                {
                    if (adorner == null)
                    {
                        if (isVisible)
                        {
                            adorner = new ShortcutAdorner(element);
                            layer.Add(adorner);
                            SetShortcutAdorner(element, adorner);
                        }
                    }
                    else
                    {
                        if (!isVisible)
                        {
                            layer.Remove(adorner);
                            SetShortcutAdorner(element, null);
                            adorner = null;
                        }
                    }

                    if (adorner != null)
                    {
                        string keyText = key.ToString();

                        if (key >= Key.D0 && key <= Key.D9)
                        {
                            keyText = keyText.Substring(1);
                        }
                        adorner.SetShortcutKey(keyText);
                        adorner.SetPosition(offset, horizontalAlignment, verticalAlignment);
                    }
                }
            }
        }
Exemplo n.º 3
0
 public static void SetShortcutAdorner(UIElement obj, ShortcutAdorner value)
 {
     obj.SetValue(ShortcutAdornerProperty, value);
 }
Exemplo n.º 4
0
 public static void SetShortcutAdorner(UIElement obj, ShortcutAdorner value)
 {
     obj.SetValue(ShortcutAdornerProperty, value);
 }