How to Programmatically show a WPF/C# Windows.Control.ToolTip?

后端 未结 7 2026
温柔的废话
温柔的废话 2020-12-25 12:01

There doesn\'t seem to be a .Show() kind of method for the Windows.Control.ToolTip, incl in ToolTipService.

7条回答
  •  温柔的废话
    2020-12-25 13:00

    Finally i ended with this .. and it's working fantastic ..

                Popup myPopup = new Popup();
                myPopup.PlacementTarget = control; //FrameworkElement where you want to show this tooltip             
                myPopup.Placement = PlacementMode.Top;
                myPopup.PopupAnimation = PopupAnimation.Slide;
    
                myPopup.AllowsTransparency = true;
                TextBlock popupText = new TextBlock();
                popupText.Text = ErrorMessage; //Message you want to show
                popupText.Background = Brushes.AliceBlue;
                popupText.Foreground = Brushes.Red;
                //popupText.FontSize = 12;                
                popupText.TextWrapping = TextWrapping.Wrap;
                myPopup.Child = popupText;
                // popup1.CustomPopupPlacementCallback =
                // new CustomPopupPlacementCallback(placePopup);
    
                //myPopup.HorizontalOffset = control.ActualWidth - popupText.ActualWidth;
                control.ToolTip = myPopup;
                myPopup.IsOpen = true;
                myPopup.StaysOpen = false;
    

提交回复
热议问题