Search code examples
c#wpfslidertooltip

C# WPF Slider AutoToolTipPlacement styling


Right now I am stuck on how to style a tooltip which is in AutoToolTipPlacement of a Slider. Is there any method to do it? I need to be able to change the structure and the text of the tooltip.

During my research I have found this https://joshsmithonwpf.wordpress.com/2007/09/14/modifying-the-auto-tooltip-of-a-slider/ , but can't figure out how to style.


Solution

  • Ok, when the AutoToolTipPlacement is enabled, it shows the tooltip, which I have to style. The answer that I found very prosaic - just use a style on a C# demand. So, we have the simple addition to the code from https://joshsmithonwpf.wordpress.com/2007/09/14/modifying-the-auto-tooltip-of-a-slider/

    private ToolTip AutoToolTip
    {
        get
        {
            if (_autoToolTip == null)
            {
                FieldInfo field = typeof(Slider).GetField(
                    "_autoToolTip",
                    BindingFlags.NonPublic | BindingFlags.Instance);
    
                _autoToolTip = field.GetValue(this) as ToolTip;
    
                _autoToolTip.Style = this.FindResource("SomeCoolStyle") as Style;
            }
    
            return _autoToolTip;
        }
    }