拖动时WPF Thumb设置光标

时间:2013-10-20 15:16:46

标签: wpf wpf-controls

我正在使用拇指控件作为尺寸控制。当我在拇指上移动时,我将光标设置为SizeWE。但是,当我按下鼠标以启动拖动操作时。光标返回指针。

我在拖动过程中尝试过明确地设置光标,但这不起作用。想法?

<Style x:Key="HorizontalSizeThumbStyle" TargetType="{x:Type Thumb}">
<Setter Property="Template">
  <Setter.Value>
    <ControlTemplate TargetType="{x:Type Thumb}">
      <Rectangle Name="thumb" Width="1" Stroke="{StaticResource AppBackgroundBrush}" StrokeThickness="0.5" Cursor="SizeWE">
        <Rectangle.Fill>
          <SolidColorBrush Color="{StaticResource AppBackgroundColor}" />
        </Rectangle.Fill>
      </Rectangle>
      <ControlTemplate.Triggers>
        <Trigger Property="IsDragging" Value="True">
          <Setter TargetName="thumb" Property="Stroke" Value="{StaticResource PressedBrush}" />
          <Setter TargetName="thumb" Property="Cursor" Value="SizeWE" />
        </Trigger>
      </ControlTemplate.Triggers>
    </ControlTemplate>
  </Setter.Value>
</Setter>
</Style>

1 个答案:

答案 0 :(得分:2)

从IsDragging处理程序中删除TargetName:

<Setter Property="Cursor" Value="SizeWE" />

而不是:

<Setter TargetName="thumb" Property="Cursor" Value="SizeWE" />