WPF - 按下按钮时的外部效果
我在WPF中有一个按钮,当按下按钮时,它会产生一个外部效果。然而,当按钮没有被按下时,效果发生,只有按下按钮时,我会如何使效果发生?WPF - 按下按钮时的外部效果
这是我的XAML:
<Button.Effect> <DropShadowEffect
BlurRadius="20" ShadowDepth="0" Color="DarkBlue">
</DropShadowEffect>
</Button.Effect>
</Button>
这是我编辑的代码:
<Button x:Name="button" Content="Button" HorizontalAlignment="Left" Margin="147,131,0,0" VerticalAlignment="Top" Width="75" PreviewMouseDown="button_PreviewMouseDown"> <Style x:Name="Triggers" TargetType ="Button">
<Style.Triggers>
<Trigger Property="IsPressed" Value="true">
<Button.Effect>
<DropShadowEffect
BlurRadius="20" ShadowDepth="0" Color="DarkBlue">
</DropShadowEffect>
</Button.Effect>
</Trigger>
</Style.Triggers>
</Style>
</Button>
谁能告诉我,为什么它不工作?
编辑:
<menu:HomeButton x:Name="BtnHome" PreviewMouseDown="BtnHome_PreviewMouseDown" TouchDown="BtnHome_TouchDown" > <Button.Style>
<Style TargetType="Button">
<Style.Triggers>
<Trigger Property="IsPressed" Value="true">
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect
BlurRadius="20" ShadowDepth="0" Color="DarkBlue"/>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
</menu:HomeButton>
回答:
可以使用Style
属性和触发IsPressed
:
<Button Content="Button"> <Button.Style>
<Style TargetType="Button">
<Style.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect BlurRadius="20" ShadowDepth="0" Color="DarkBlue"/>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
借鉴https://stackoverflow.com/a/46279626/6741868
以上是 WPF - 按下按钮时的外部效果 的全部内容, 来源链接: utcz.com/qa/260582.html