73 lines
4.5 KiB
XML
73 lines
4.5 KiB
XML
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
xmlns:local="clr-namespace:Sample">
|
|
<!-- 确保这里的命名空间正确 -->
|
|
|
|
<!-- NeumorphicButton 的默认样式 -->
|
|
<Style TargetType="{x:Type Button}">
|
|
<!-- 基础属性设置 -->
|
|
<Setter Property="Background" Value="{DynamicResource AppBackgroundBrush}"/>
|
|
<Setter Property="Foreground" Value="{DynamicResource AppTextBrush}"/>
|
|
<Setter Property="BorderThickness" Value="0"/>
|
|
<Setter Property="Height" Value="50"/>
|
|
<Setter Property="MinWidth" Value="100"/>
|
|
<Setter Property="Padding" Value="15,5"/>
|
|
<Setter Property="HorizontalContentAlignment" Value="Center"/>
|
|
<Setter Property="VerticalContentAlignment" Value="Center"/>
|
|
<Setter Property="Cursor" Value="Hand"/>
|
|
|
|
<!-- 控件模板 -->
|
|
<Setter Property="Template">
|
|
<Setter.Value>
|
|
<ControlTemplate TargetType="{x:Type Button}">
|
|
|
|
<!-- 【关键修正】将不同状态的 Effect 定义为资源 -->
|
|
<ControlTemplate.Resources>
|
|
<!-- 正常状态的阴影 -->
|
|
<DropShadowEffect x:Key="NormalDarkShadow" ShadowDepth="4" Direction="315" Color="#000000" Opacity="0.15" BlurRadius="8"/>
|
|
<DropShadowEffect x:Key="NormalLightShadow" ShadowDepth="-4" Direction="135" Color="#FFFFFF" Opacity="0.7" BlurRadius="8"/>
|
|
|
|
<!-- 悬停状态的阴影 -->
|
|
<DropShadowEffect x:Key="HoverDarkShadow" ShadowDepth="6" Direction="315" Color="#000000" Opacity="0.15" BlurRadius="12"/>
|
|
<DropShadowEffect x:Key="HoverLightShadow" ShadowDepth="-6" Direction="135" Color="#FFFFFF" Opacity="0.7" BlurRadius="12"/>
|
|
|
|
<!-- 按下状态的阴影 (内阴影效果) -->
|
|
<DropShadowEffect x:Key="PressedDarkShadow" ShadowDepth="-3" Direction="135" Color="#FFFFFF" Opacity="0.6" BlurRadius="6"/>
|
|
<DropShadowEffect x:Key="PressedLightShadow" ShadowDepth="3" Direction="315" Color="#000000" Opacity="0.1" BlurRadius="6"/>
|
|
</ControlTemplate.Resources>
|
|
|
|
<!-- 视觉树 (Visual Tree) -->
|
|
<Border x:Name="RootBorder"
|
|
Background="{TemplateBinding Background}"
|
|
CornerRadius="12"
|
|
Effect="{StaticResource NormalDarkShadow}">
|
|
<!-- 应用默认的深色阴影 -->
|
|
<Grid x:Name="InnerGrid"
|
|
Effect="{StaticResource NormalLightShadow}">
|
|
<!-- 应用默认的亮色阴影 -->
|
|
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
|
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
|
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
|
|
Margin="{TemplateBinding Padding}"/>
|
|
</Grid>
|
|
</Border>
|
|
|
|
<!-- 【关键修正】触发器现在操作的是 Border 和 Grid 的 Effect 属性 -->
|
|
<ControlTemplate.Triggers>
|
|
<!-- 鼠标悬停时,替换整个 Effect 对象 -->
|
|
<Trigger Property="IsMouseOver" Value="True">
|
|
<Setter TargetName="RootBorder" Property="Effect" Value="{StaticResource HoverDarkShadow}"/>
|
|
<Setter TargetName="InnerGrid" Property="Effect" Value="{StaticResource HoverLightShadow}"/>
|
|
</Trigger>
|
|
|
|
<!-- 鼠标按下时,替换成“内阴影”效果的 Effect 对象 -->
|
|
<Trigger Property="IsPressed" Value="True">
|
|
<Setter TargetName="RootBorder" Property="Effect" Value="{StaticResource PressedDarkShadow}"/>
|
|
<Setter TargetName="InnerGrid" Property="Effect" Value="{StaticResource PressedLightShadow}"/>
|
|
</Trigger>
|
|
</ControlTemplate.Triggers>
|
|
</ControlTemplate>
|
|
</Setter.Value>
|
|
</Setter>
|
|
</Style>
|
|
</ResourceDictionary> |