gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 00:42:30 25 4
gpt4 key购买 nike

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

        <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>

最佳答案

您可以绑定(bind)Path.FillForeground按钮的属性并修改按钮样式中的前景:

<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>

关于wpf - 如何使用 XAML 中的触发器更改路径填充(在按钮上),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14562186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com