How can I show a Balloon Tip over a textbox?

qJake picture qJake · Sep 24, 2011 · Viewed 20.6k times · Source

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 to use Microsoft's native balloon control for this. How would I implement this into my application?

Answer

ARZ picture ARZ · Sep 28, 2011

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!