0

For the documentation of a WPF application I need a screen-shot of it with all available tool-tip activated.

I tried to combine screenshots of the application with one tool-tip activated on each image, but I'm not a PS/Gimp expert and it's a lot of images to combine.

Orace
  • 7,822
  • 30
  • 45

1 Answers1

0

Based on this answer you can iterate thru all children of type FrameworkElement in the application to activate theirs tool-tip (if any).

To activate a tool-tip you cans use this answer.

Finally you can add a display all tool-tip button in your application and the code behind will be like this:

private void DisplayAllToolTips_OnClick(object sender, RoutedEventArgs e)
{
    foreach (var element in FindVisualChildren<FrameworkElement>(this))
    {
        if (element.ToolTip == null)
            continue;

        var toolTip = element.ToolTip as ToolTip ??
                      new ToolTip {Content = element.ToolTip};

        element.ToolTip = toolTip;

        toolTip.PlacementTarget = element;
        toolTip.Placement = PlacementMode.Relative;
        toolTip.HorizontalOffset = 6;
        toolTip.VerticalOffset = -6;
        toolTip.Opacity = 0.8;

        toolTip.IsOpen = true;
    }
}

private static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
{
    if (depObj == null)
        yield break;

    for (var i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
    {
        var child = VisualTreeHelper.GetChild(depObj, i);
        if (child is T t)
            yield return t;

        foreach (var childOfChild in FindVisualChildren<T>(child))
            yield return childOfChild;
    }
}
Orace
  • 7,822
  • 30
  • 45