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