Adding a second finger to a slider control in WPF

I'm trying to make a range control, which basically is a slider with an extra thumb. The only code I found for already built is here.

http://www.codeplex.com/AvalonControlsLib

Throughout life, I cannot get a tooltip to display over each thumb (with the current value) while it is moving. It will show a quick tip for the mouse, but it disappears when you move your thumb. Does anyone know anything about this particular control or how to add a second pointer to a slider control and use it in the same way? I found this basic question in several unanswered forums other than linking. Of course, people always mention how easy it is to do it, without showing or explaining how you will do it. Thanks in advance.

Bean

+3
source share
2 answers

, Avalon Controls : Avalon Controls

PART_LeftToolTip

<ControlTemplate TargetType="{x:Type Controls:RangeSlider}">
    <StackPanel Orientation="Horizontal" Name="PART_RangeSliderContainer">
         <RepeatButton Name="PART_LeftEdge"/>                        
         <Thumb Name="PART_LeftThumb" Cursor="SizeWE">
               <Thumb.ToolTip>
                     <ToolTip Name="PART_LeftToolTip" />        
               </Thumb.ToolTip>
          </Thumb>                                             
          <Thumb Name="PART_MiddleThumb" Cursor="ScrollWE" MinWidth="1"/>
          <Thumb Name="PART_RightThumb" Cursor="SizeWE">
                <Thumb.ToolTip>
                      <ToolTip Name="PART_RightToolTip" />
                </Thumb.ToolTip>
          </Thumb>
          <RepeatButton Name="PART_RightEdge"/>
      </StackPanel>
</ControlTemplate>

RangeSlider

TemplatePart(Name = "PART_LeftToolTip", Type = typeof(ToolTip)),
TemplatePart(Name = "PART_RightToolTip", Type = typeof(ToolTip))]
public sealed class RangeSlider : Control

OnApplyTemplate

_leftPreviewToolTip = EnforceInstance<ToolTip>("PART_LeftToolTip");
_rightPreviewToolTip = EnforceInstance<ToolTip>("PART_RightToolTip");

InitializeVisualElements

private void InitializeVisualElementsContainer()
{
   // ** same as before ** //

   _leftPreviewToolTip.PlacementTarget = _leftThumb;
   _rightPreviewToolTip.PlacementTarget = _rightThumb;
}

, , . , . , ShowLeftTooltip, LeftThumbDragDelta CenterThumbDragDelta .

private void ShowLeftToolTip()
{
    _leftPreviewToolTip.IsOpen = AutoToolTip;
    // This is a little trick to cause the ToolTip to update its position next to the Thumb
    _leftPreviewToolTip.HorizontalOffset = _leftPreviewToolTip.HorizontalOffset == 0.0 ? 0.001 : 0.0;
}

- , , -.

, .

, . - , .

+3

IsOpen ToolTip IsDragging Thumb

0

Source: https://habr.com/ru/post/1710533/


All Articles