jenokizm
jenokizm

Reputation: 9

System.Windows.Forms.ToolTip showing in WPF window

I'm trying to show a tooltip from Windows.Forms in wpf window. I need only this type of hint.

1 option:

ToolTip1.Show("Hello!", Application.Current.MainWindow, point, 5000);

intellisense error:

Error CS1503 Argument 2: Can not convert from "System.Windows.Window" to "System.Windows.Forms.IWin32Window"

2 option:

System.Windows.Forms.IWin32Window win32Window = new System.Windows.Forms.NativeWindow();
((System.Windows.Forms.NativeWindow)win32Window).AssignHandle(new System.Windows.Interop.WindowInteropHelper(Application.Current.MainWindow).Handle);
ToolTip1.Show("Hello!", win32Window, point, 5000);

runtime error:

An exception is thrown: "System.ArgumentNullException" in mscorlib.dll Additional information: The key can not be undefined.

Upvotes: 0

Views: 502

Answers (1)

Mihail Stancescu
Mihail Stancescu

Reputation: 4138

As far as I know windows can not have tool tips.

To add tool tips for WPF controls you can use the built-in ToolTipClass.

<Button Content="Submit">
  <Button.ToolTip>
    <ToolTip>
        <StackPanel>
            <TextBlock FontWeight="Bold">Submit Request</TextBlock>
            <TextBlock>Submits the request to the server.</TextBlock>
        </StackPanel>
    </ToolTip>
  </Button.ToolTip>
</Button>

If you really need the tool tip for the window, one possible solution is to "simulate" the window:

  • Make the window client area smaller and create a custom title bar and window border (make it so you can resize it, drag it, etc.)
  • Add a invisible space to show the tool tip
  • Set the tool tip for the "title bar"

Upvotes: 1

Related Questions