当前位置: 首页 > 编程语言 > C#

WPF:ControlTemplate的IsPressed触发器不工作Share

时间:2023-04-11 02:55:56 C#

WPF:ControlTemplate的IsPressed触发器不工作ImageButton包包含依赖项属性:publicImageSourceDisabledImageSource{get{return(ImageSource)GetValue(DisabledImageSourceProperty);}set{SetValue(DisabledImageSourceProperty,value);}}publicImageSourceNormalImageSource{get{return(ImageSource)GetValue(NormalImageSourceProperty);}set{SetValue(NormalImageSourceProperty,value);}}publicImageSourceHoverImageSource{get{return(ImageSource)GetValue(HoverImageSourceProperty);}set{SetValue(HoverImageSourceProperty,value);}}publicImageSourcePushedImageSource{get{return(ImageSource)GetValue(PushedImageSourceProperty);}set{SetValue(PushedImageSourceProperty,value);}}publicstaticreadonlyDependencyPropertyDisabledImageSourceProperty=DependencyProperty.Register("DisabledImageSource",typeof(ImageSource),typeof(ImageButton),newUIPropertyMetadata());publicstaticreadonlyDependencyPropertyNormalImageSourceProperty=DependencyProperty.Register("NormalImageSource",typeof(ImageSource),typeof(ImageButton),newUIPropertyMetadata());publicstaticreadonlyDependencyPropertyHoverImageSourceProperty=DependencyProperty.Register("HoverImageSource",typeof(ImageSource),typeof(ImageButton),newUIPropertyMetadata());公共staticreadonlyDependencyPropertyPushedImageSourceProperty=DependencyProperty.Register("PushedImageSource",typeof(ImageSource),typeof(ImageButton),newUIPropertyMetadata());它的样式定义如下:我永远看不到我在PushedImageSource中设置的图像,除了IsPressed,我不知道为什么。需要任何帮助吗?编辑1:这是测试它的xaml代码您的触发器不是相互排斥的,在这种情况下,触发器添加到Triggers集合的顺序开始起作用。在IsPressed触发器设置正确的图像之后,您的最后一个触发器IsMouseOver会覆盖Source属性,因为只有在鼠标悬停时才会按下按钮(当然是在使用鼠标时)。尝试设置Triggers集合中的最后一个IsPressed触发器,即使IsMouseOver也为真,也会应用IsPressed触发器。好的,所以我找到了一个有点丑陋的解决方法,但它有效更多关于C#学习教程,希望大家多多关注—本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处: