Files
ShrlAlgoToolkit/Melskin/Controls/Decorations/SlotBorder.xaml
2026-02-20 15:31:44 +08:00

101 lines
6.1 KiB
XML

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:conv="clr-namespace:Melskin.Converters"
xmlns:dec="clr-namespace:Melskin.Controls.Decorations"
xmlns:internal="clr-namespace:Melskin.Converters.Internal">
<Style TargetType="{x:Type dec:SlotBorder}">
<Setter Property="Focusable" Value="False" />
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundNormalBrush}" />
<Setter Property="LightShadowBrush" Value="{DynamicResource LightShadowBrush}" />
<Setter Property="DarkShadowBrush" Value="{DynamicResource DarkShadowBrush}" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
<Setter Property="CornerRadius" Value="4" />
<Setter Property="Padding" Value="2" />
<Setter Property="ShaderEnabled" Value="True" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="FontSize" Value="14" />
<Setter Property="Intensity" Value="1" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type dec:SlotBorder}">
<Grid>
<!-- 隐藏阴影的时候呈现背景色 -->
<!-- 默认4的边距显示光影效果 -->
<Border
Margin="4"
Background="{TemplateBinding Background}"
CornerRadius="{TemplateBinding CornerRadius}" />
<!-- 内阴影效果 -->
<Grid Visibility="{TemplateBinding ShaderEnabled, Converter={x:Static conv:BooleanToVisibilityConverter.CollapsedInstance}}">
<!-- 背景填充 -->
<Rectangle Fill="{TemplateBinding Background}" />
<!-- 左上阴影 -->
<Border
Margin="{TemplateBinding Intensity,
Converter={x:Static internal:IntensityToSlotShadowMarginConverter.Instance}}"
Background="{TemplateBinding DarkShadowBrush}"
CornerRadius="{TemplateBinding CornerRadius}" />
<!-- 右下高亮 -->
<Border
Margin="{TemplateBinding Intensity,
Converter={x:Static internal:IntensityToSlotLightMarginConverter.Instance}}"
Background="{TemplateBinding LightShadowBrush}"
CornerRadius="{TemplateBinding CornerRadius}" />
<!-- 背景中央 -->
<Border
Margin="{TemplateBinding Intensity,
Converter={x:Static internal:IntensityToSlotMarginConverter.Instance}}"
Background="{TemplateBinding Background}"
CornerRadius="{TemplateBinding CornerRadius}" />
<!-- 裁切区域 -->
<Grid.Clip>
<MultiBinding
Converter="{x:Static internal:CreateSlotClipGeometryConverter.Instance}"
ConverterParameter="4"
Mode="OneWay">
<Binding
Mode="OneWay"
Path="CornerRadius"
RelativeSource="{RelativeSource TemplatedParent}" />
<Binding
Mode="OneWay"
Path="ActualWidth"
RelativeSource="{RelativeSource TemplatedParent}" />
<Binding
Mode="OneWay"
Path="ActualHeight"
RelativeSource="{RelativeSource TemplatedParent}" />
</MultiBinding>
</Grid.Clip>
<Grid.Effect>
<BlurEffect Radius="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Intensity, Converter={x:Static internal:IntensityToSlotBlurConverter.Instance}, Mode=OneWay}" />
</Grid.Effect>
</Grid>
<!-- 显示边框和内容 -->
<!-- 默认4的边距显示光影效果 -->
<Border
Margin="4"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}">
<ContentPresenter
x:Name="contentPresenter"
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Focusable="False"
RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
TextElement.Foreground="{TemplateBinding Foreground}" />
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>