如何使用XAML中的触发器更改路径填充(在按钮上)

编程入门 行业动态 更新时间:2024-10-27 18:30:39
本文介绍了如何使用XAML中的触发器更改路径填充(在按钮上)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个带有路径的按钮作为图标,当鼠标悬停在整个按钮(不仅是路径)上时,我想更改路径的填充.谢谢.

I have a button with a path as icon,i want to change the fill of the path when the mouse is over the whole button (not only the path). Thanks.

<Button Name="Test_Button" Width="220" Height="80" Padding="2"> <Canvas Width="76" Height="76" Clip="F1 M 0,0L 76,0L 76,76L 0,76L 0,0"> <Path Canvas.Left="19" Canvas.Top="19" Width="38" Height="38" Data="F1 M 35,19L 41,19L 41,35L 57,35L 57,41L 41,41L 41,57L 35,57L 35,41L 19,41L 19,35L 35,35L 35,19 Z " Stretch="Fill"> <Path.Style> <Style TargetType="{x:Type Path}"> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Path.Fill" Value="Red" /> </Trigger> <Trigger Property="IsMouseOver" Value="False"> <Setter Property="Path.Fill" Value="Gray" /> </Trigger> </Style.Triggers> </Style> </Path.Style> </Path> </Canvas> </Button>

推荐答案

您可以将Path.Fill绑定到按钮的前景属性,并以按钮样式修改前景:

You may bind Path.Fill to the Foreground property of the Button and modify the Foreground in a Button Style:

<Button Name="Test_Button" Width="220" Height="80" Padding="2"> <Canvas Width="76" Height="76" Clip="F1 M 0,0L 76,0L 76,76L 0,76L 0,0"> <Path Canvas.Left="19" Canvas.Top="19" Width="38" Height="38" Stretch="Fill" Fill="{Binding Foreground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Button}}" Data="F1 M 35,19L 41,19L 41,35L 57,35L 57,41L 41,41L 41,57L 35,57L 35,41L 19,41L 19,35L 35,35L 35,19 Z"> </Path> </Canvas> <Button.Style> <Style TargetType="Button"> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Foreground" Value="Red" /> </Trigger> <Trigger Property="IsMouseOver" Value="False"> <Setter Property="Foreground" Value="Gray" /> </Trigger> </Style.Triggers> </Style> </Button.Style> </Button>

更多推荐

如何使用XAML中的触发器更改路径填充(在按钮上)

本文发布于:2023-11-12 04:56:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580566.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:触发器   如何使用   路径   按钮   XAML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!