【问题标题】:How can I use IsPressed property in ControlTemplate of Thumb?如何在 Thumb 的 ControlTemplate 中使用 IsPressed 属性?
【发布时间】:2019-03-13 14:36:34
【问题描述】:

我想重写拇指的 ControlTemplate。

代码如下:

<ControlTemplate x:Key="123" TargetType="Thumb">
    <Border Name="B"></Border>
    <ControlTemplate.Triggers>
        <Trigger Property="IsPressed" Value="true">
            <Setter Property="Background" TargetName="B" Value="#575757"/>
        </Trigger>
        <Trigger Property="IsMouseOver" Value="true">
            <Setter Property="Background" TargetName="B" Value="Red"/>
        </Trigger>
    </ControlTemplate.Triggers>
</ControlTemplate>

但是,VS 2019 RC1 报错:
奇怪的是,IsMouseOver 没问题,但 IsPressed 报错。

我找到了微软的官方模板如下:https://docs.microsoft.com/en-us/dotnet/framework/wpf/controls/thumb-styles-and-templates

但是现在官方模板是使用VisualState而不是trigger。

我想知道如何通过使用触发器来使用 IsPressed 属性。

也许你会问我为什么不用VisualState?我在项目中写了几个自定义控件,我不想要使用VisualState的东西和使用Trigger的东西,这太混乱了。我只想所有都是触发器。

谢谢。

【问题讨论】:

  • Thumb 没有 IsPressed 属性?
  • 但是正如微软官方模板所说,视觉状态下有一个press属性,我认为trigger中也有一个press属性。

标签: wpf


【解决方案1】:

Thumb 根据Docs 没有IsPressed 属性

您可以使用其他属性,例如IsDragging

获取Thumb控件是否有逻辑焦点和鼠标捕获以及鼠标左键是否被按下。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多