WPF:ControlTemplate的IsPressed触发器无法正常工作

我使用名为ImageButton的自定义控件来显示具有不同图像的按钮。 ImageButton包含依赖项属性:

 public ImageSource DisabledImageSource { get { return (ImageSource)GetValue(DisabledImageSourceProperty); } set { SetValue(DisabledImageSourceProperty, value); } } public ImageSource NormalImageSource { get { return (ImageSource)GetValue(NormalImageSourceProperty); } set { SetValue(NormalImageSourceProperty, value); } } public ImageSource HoverImageSource { get { return (ImageSource)GetValue(HoverImageSourceProperty); } set { SetValue(HoverImageSourceProperty, value); } } public ImageSource PushedImageSource { get { return (ImageSource)GetValue(PushedImageSourceProperty); } set { SetValue(PushedImageSourceProperty, value); } } public static readonly DependencyProperty DisabledImageSourceProperty = DependencyProperty.Register("DisabledImageSource", typeof(ImageSource), typeof(ImageButton), new UIPropertyMetadata()); public static readonly DependencyProperty NormalImageSourceProperty = DependencyProperty.Register("NormalImageSource", typeof(ImageSource), typeof(ImageButton), new UIPropertyMetadata()); public static readonly DependencyProperty HoverImageSourceProperty = DependencyProperty.Register("HoverImageSource", typeof(ImageSource), typeof(ImageButton), new UIPropertyMetadata()); public static readonly DependencyProperty PushedImageSourceProperty = DependencyProperty.Register("PushedImageSource", typeof(ImageSource), typeof(ImageButton), new UIPropertyMetadata()); 

它的风格定义如下:

                           

除了IsPressedIsPressed 。 我永远看不到我在PushedImageSource设置的图像,我无法弄清楚为什么。 任何帮助都会被appriciated 🙂

编辑1:

这是测试它的xaml代码

               

您的触发器不是互斥的,在这种情况下触发器添加到Triggers集合的顺序开始起作用。 在IsPressed触发器设置正确的图像后,您的最后一个触发器IsMouseOver会覆盖Source属性,因为只有在鼠标结束时(当然使用鼠标时)才按下按钮。

尝试在Triggers集合中设置最后的IsPressed触发器,即使IsMouseOver也为真,也会应用IsPressed触发器。

好的,所以我找到了一种有点难看的解决方法,但它确实有效