C# WPF 滑块 AutoToolTipPlacement 样式

问题描述 投票:0回答:1

现在我陷入了如何设计滑块 AutoToolTipPlacement 中的工具提示样式的困境。有什么方法可以做到吗?我需要能够更改工具提示的结构和文本。

在我的研究过程中,我发现了这个https://joshsmithonwpf.wordpress.com/2007/09/14/modifying-the-auto-tooltip-of-a-slider/,但不知道如何设计样式.

c# wpf slider tooltip
1个回答
0
投票

好的,当启用 AutoToolTipPlacement 时,它会显示工具提示,我必须对其进行样式设置。我发现答案非常平淡——只需根据 C# 需求使用样式即可。因此,我们对 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;
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.