How can I show a Balloon Tip over a textbox?

后端 未结 4 1449
情话喂你
情话喂你 2020-12-24 15:28

I have a C# WPF application using XAML and MVVM. My question is: How can I show a balloon tooltip above a text box for some invalid data entered by the user?

I want

4条回答
  •  醉话见心
    2020-12-24 16:26

    Just add a reference to System.Windows.Forms and C:\Program Files\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\WindowsFormsIntegration.dll and then:

        WindowsFormsHost host =new WindowsFormsHost();
    
        var toolTip1 = new System.Windows.Forms.ToolTip();
    
        toolTip1.AutoPopDelay = 5000;
        toolTip1.InitialDelay = 1000;
        toolTip1.ReshowDelay = 500;
        toolTip1.ShowAlways = true;
        toolTip1.IsBalloon = true;
        toolTip1.ToolTipIcon = System.Windows.Forms.ToolTipIcon.Info;
        toolTip1.ToolTipTitle = "Title:";
    
        System.Windows.Forms.TextBox tb = new System.Windows.Forms.TextBox();
        tb.Text="Go!";
        toolTip1.SetToolTip(tb, "My Info!");
        host.Child = tb;
        grid1.Children.Add(host);  //a container for windowsForm textBox 
    

    and this is a sample for WinForm ToolTip Ballon in WPF:

    enter image description here

    Hope this help!

提交回复
热议问题