This add-on adds three methods to the drawing objects. The methods are SetToolTipText (string), SetToolTipContent (object), and SetToolTipContentFactory (Func<object>). You only need to call one of these methods in order to apply your tooltip. The one you use will depend on your scenario.
Scenario One
In the simple case, you can use the SetToolTipText method to display a simple string.
var drawing = Draw.Dot(...); drawing.SetToolTipText("Hello, world!");
Draw.Dot(...).SetToolTipText("Hello, world!");
To display controls on a few objects, you can use the SetToolTipContent method to provide your element tree.
var drawing = Draw.Dot(...); var button = new Button { Content = "Hello" }; button.Click += (_, __) => button.Content = "World"; drawing.SetToolTipContent(button);
var drawing = Draw.Dot(...); Dispatch(() => { var button = new Button { Content = "Hello" }; button.Click += (_, __) => button.Content = "World"; drawing.SetToolTipContent(button); });
To display controls on many objects, you can use the SetToolTipContentFactory method to provide your element tree. The method you provide will be called only when the tooltip is shown. After the tooltip is hidden, the object instance you returned from the factory will be eligible for garbage collection.
If you are creating custom tooltips for many drawing objects, it is recommended that you use this method since it will use the least amount of memory. Keep in mind that the function you provide can be called zero or many times.
var drawing = Draw.Dot(...); drawing.SetToolTipContentFactory(() => { var button = new Button { Content = "Hello" }; button.Click += (_, __) => button.Content = "World"; return button; });
Place the attached file in the AddOns folder.
NOTES:
- A new menu item under the Tools menu allows enabling/disabling. It does not work properly, however, after compiling. Will look for a workaround
- After compiling, the chart will need to be refreshed for existing tooltips to show. This is because the tooltips are not stored on the drawings themselves
- Be aware of captures when using lambdas. Assign indicator properties to local variables and use the local variables in the lambdas.
- There are several classes in the file. They can be put into their own files is desired
- I'm using .Net 4.7 but I believe I've used only 4.5 features in this file. If it doesn't compile for you, let me know and I will fix it
Comment