コード例 #1
0
 private static TooltipPopup GetOrCreateTooltipPopup (FrameworkElement control)
 {
     var window = control.GetParent<Window>();
     if (window == null)
         return null;
     TooltipPopup popup = GetTooltipPopup(window);
     if (popup == null) {
         popup = new TooltipPopup { Owner = window };
         SetTooltipPopup(window, popup);
         window.LocationChanged += UpdatePopup;
         window.SizeChanged += UpdatePopup;
     }
     return popup;
 }
コード例 #2
0
        private static TooltipPopup GetOrCreateTooltipPopup(FrameworkElement control)
        {
            var window = control.GetParent <Window>();

            if (window == null)
            {
                return(null);
            }
            TooltipPopup popup = GetTooltipPopup(window);

            if (popup == null)
            {
                popup = new TooltipPopup {
                    Owner = window
                };
                SetTooltipPopup(window, popup);
                window.LocationChanged += UpdatePopup;
                window.SizeChanged     += UpdatePopup;
            }
            return(popup);
        }
コード例 #3
0
        private static void UpdatePopup(object sender, EventArgs args)
        {
            var window = sender as Window;
            FrameworkElement control;

            if (window != null) // window change event, apply to previously validated control
            {
                control = GetCurrentValidatedControl(window);
            }
            else   // validated control change event
            {
                control = (FrameworkElement)sender;
                window  = control.GetParent <Window>();
            }
            if (control == null) // no controls validated yet
            {
                return;
            }
            TooltipPopup popup = GetOrCreateTooltipPopup(window);

            if (popup == null) // controls not yet loaded, can't get root window
            {
                return;
            }
            var icon = GetValidationIcon(control);

            SetCurrentValidatedControl(window, control);

            object message = GetMessage(icon);

            if (icon == null || !control.IsKeyboardFocused ||
                (message == null) ||
                (message is string && ((string)message).IsNullOrEmpty()) ||
                (message is IEnumerable <object> && !((IEnumerable <object>)message).Any()))
            {
                popup.Hide();
            }
            else
            {
                var pos          = icon.PointToScreen(new Point(0, 0));
                var popupContent = BindingOperations.GetBinding(popup, ContentControl.ContentProperty);
                if (popupContent == null || !ReferenceEquals(popupContent.Source, icon))
                {
                    BindingOperations.SetBinding(popup, ContentControl.ContentProperty,
                                                 new Binding {
                        Source = icon, Path = new PropertyPath(MessageProperty)
                    });
                }
                popup.Show();
                if (pos.X + icon.ActualWidth + PopupPosDelta + popup.Width - TooltipPopup.ShadowMargin
                    <= SystemParameters.VirtualScreenTop + SystemParameters.VirtualScreenWidth)
                {
                    popup.Left = pos.X + icon.ActualWidth + PopupPosDelta;
                    popup.Top  = pos.Y - PopupPosDelta;
                }
                else
                {
                    popup.Left = pos.X + icon.ActualWidth - popup.Width + TooltipPopup.ShadowMargin;
                    popup.Top  = pos.Y + icon.ActualHeight + PopupPosDelta;
                }
            }
        }
コード例 #4
0
 private static void SetTooltipPopup(Window d, TooltipPopup value)
 {
     d.SetValue(TooltipPopupProperty, value);
 }
コード例 #5
0
 private static void SetTooltipPopup (Window d, TooltipPopup value)
 {
     d.SetValue(TooltipPopupProperty, value);
 }