复制后可直接粘贴给 AI,让它按指南生成效果文件

锁屏动画开发指南

锁屏程序基于 WPF 开发,动画由松散 XAML 驱动:把 .xaml 存成文件后,在「锁屏动画」页点「导入动画」选择它即可。导入时先经白名单校验,通过后才复制到用户数据目录并出现在列表里。

一、最简文件

保存为 .xaml 文件后在「锁屏动画」页导入即可生效,不需要注释或声明:

<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <TextBlock Text="Hello ShadowLock" Foreground="White"
               HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
  • 根元素必须是 FrameworkElement,否则加载失败。

  • 元素须在 http://schemas.microsoft.com/winfx/2006/xaml/presentation 命名空间内,xmlns 只能映射该命名空间或 x。

二、可用的元素

白名单外一律拒绝。

类别

可用类型

布局 / 容器

Grid(含 ColumnDefinition、RowDefinition)、Border、Canvas、StackPanel、WrapPanel、DockPanel、UniformGrid、Viewbox

文本

TextBlock、Run、Span、Bold、Italic、Underline、LineBreak

形状

Rectangle、Ellipse、Line、Path、Polygon、Polyline;Path 的部件 PathFigure、PathFigureCollection、PathSegmentCollection、PointCollection、DoubleCollection、各类 Segment

画刷

SolidColorBrush、LinearGradientBrush、RadialGradientBrush、GradientStop

变换

RotateTransform、ScaleTransform、TranslateTransform、SkewTransform、MatrixTransform、TransformGroup

特效与样式

BlurEffect、DropShadowEffect;Style、Setter、Trigger、EventTrigger

动画

类名含 Animation / KeyFrame,或以 Ease / Storyboard / Geometry 结尾,如 DoubleAnimation、Storyboard

以下两类属主动拦截:

  • 模板(ControlTemplate、DataTemplate、ItemsControl):内部不受白名单约束,会绕过校验。

  • 代码原语:x:Static、x:Type、x:Code、x:Reference、ObjectDataProvider,以及标记扩展中出现 clr-namespace、assembly=。

三、内置绑定

根元素 DataContext 是内置时钟源,每秒刷新:

绑定

输出

{Binding time}

14:08:32

{Binding dateShort}

2026-3-6

{Binding dateChinese}

2026年3月6日

{Binding dateChineseWeek}

2026年3月6日 星期五

无法在 XAML 内调用 DateTime.Now。

四、校验与排错

导入时就会校验:不通过直接弹出原因,文件不会进入列表。如果已导入的动画没能正常展示,多半是元素不合法,可查看失败原因(「通用设置 → 日志文件夹 → 查看」):

外挂效果 -> [Sample.xaml] 安全校验未通过,已拒绝加载:Sample.xaml | 包含未允许的元素类型(已拦截):Button

槽引用用错位置同样会被拦截,例如把画刷引用到 Color 属性(应为 ShadowLock.EffectColor.<Key>.Color):

外挂效果 -> [x.xaml] 安全校验未通过,已拒绝加载:x.xaml | 属性 Color 需要颜色值而非画刷:引用应加 .Color 后缀

只做类型层拦截,导入的 XAML 来源自行负责。

五、程序内编辑参数

默认把颜色、文字、字号写死在 XAML 里即可。要让某个值能在程序中维护和调整,做两件事:在第一段注释里声明一行,在正文里引用它。

<!--
  Name: 标题
  Accent=主色|#0078D4
  Title=标题|今日值班
  TitleSize=字号|36
-->
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
    <TextBlock Text="{DynamicResource ShadowLock.EffectText.Title}"
               Foreground="{DynamicResource ShadowLock.EffectColor.Accent}"
               FontSize="{DynamicResource ShadowLock.EffectSize.TitleSize}"/>
</Grid>

注释里不写类型:一行声明是颜色、文字还是字号,取决于正文用哪个名字引用它。引用名写错类型会跟着变——颜色值若被 EffectText. 引用,就只是屏幕上显示 #0078D4 这几个字。

正文写法

该项变成

{DynamicResource ShadowLock.EffectColor.<Key>}

颜色(画刷)

{DynamicResource ShadowLock.EffectColor.<Key>.Color}

颜色本身(Color)

{DynamicResource ShadowLock.EffectText.<Key>}

文字(string)

{DynamicResource ShadowLock.EffectSize.<Key>}

尺寸(double)

属性要的是 Color 而不是画刷时(GradientStop.Color、DropShadowEffect.Color),引用名加 .Color 后缀;两者填的是同一个颜色值:

<LinearGradientBrush>
    <GradientStop Offset="0" Color="{DynamicResource ShadowLock.EffectColor.Accent.Color}"/>
    <GradientStop Offset="1" Color="Black"/>
</LinearGradientBrush>
  • 声明行统一写法 <Key>=<显示名>|<默认值>;<Key> 限 [A-Za-z0-9_],<显示名> 必填,就是程序设置面板里该项的标签。

  • 颜色值 #RRGGBB 或 #AARRGGBB(前两位为透明度);文字默认值不能含 | 或换行;尺寸取值 1–10000。

六、完整示例
<!--
  ShadowLockEffect
  Name: 示例动画
  Description: 字号、颜色、文字、渐变、时间五类写法对照(硬编码 / 可配置 / 内置绑定)
  ConfigColor=示例颜色|#FF0078D4
  ConfigText=示例文字|这段文字可在「自定义」面板中修改
  ConfigSize=示例字号|36
-->

<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      IsHitTestVisible="False">

    <Border HorizontalAlignment="Center" VerticalAlignment="Center"
            MaxWidth="720" Padding="26,22" CornerRadius="12" Background="#D9101010">

        <StackPanel>
            <TextBlock Text="外挂效果配置方式" FontSize="22" FontWeight="Bold"
                       Foreground="#FFFFFFFF" TextAlignment="Center"/>
            <TextBlock Margin="0,6,0,0" FontSize="12" Foreground="#FF9A9A9A"
                       TextAlignment="Center" TextWrapping="Wrap"
                       Text="同一个属性两种写法:写死在 XAML 里,或在注释头声明后由「自定义」面板修改;时间只能走内置绑定。"/>

            <!-- ① 字号:只变字号,颜色统一白色便于对比 -->
            <TextBlock Margin="0,18,0,6" FontSize="14" FontWeight="Bold" Foreground="#FF7FD1FF" Text="① 字号 FontSize"/>
            <StackPanel Orientation="Horizontal" Margin="0,0,0,6">
                <TextBlock Width="150" FontSize="12" Foreground="#FF8C8C8C" VerticalAlignment="Center" Text="硬编码"/>
                <TextBlock FontSize="20" Foreground="#FFFFFFFF" VerticalAlignment="Center" Text="字号写死 20"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal">
                <TextBlock Width="150" FontSize="12" Foreground="#FF8C8C8C" VerticalAlignment="Center" Text="可配置(默认 36)"/>
                <TextBlock Foreground="#FFFFFFFF" VerticalAlignment="Center" FontSize="{DynamicResource ShadowLock.EffectSize.ConfigSize}" Text="字号取 Size 声明"/>
            </StackPanel>

            <!-- ② 颜色:只变前景色,字号统一 20 便于对比 -->
            <TextBlock Margin="0,16,0,6" FontSize="14" FontWeight="Bold" Foreground="#FF7FD1FF" Text="② 颜色 Foreground"/>
            <StackPanel Orientation="Horizontal" Margin="0,0,0,6">
                <TextBlock Width="150" FontSize="12" Foreground="#FF8C8C8C" VerticalAlignment="Center" Text="硬编码"/>
                <TextBlock FontSize="20" Foreground="#FFFFD700" VerticalAlignment="Center" Text="颜色写死为金色"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal">
                <TextBlock Width="150" FontSize="12" Foreground="#FF8C8C8C" VerticalAlignment="Center" Text="可配置(默认蓝)"/>
                <TextBlock FontSize="20" VerticalAlignment="Center" Foreground="{DynamicResource ShadowLock.EffectColor.ConfigColor}" Text="颜色取 Color 声明"/>
            </StackPanel>

            <!-- ③ 文字:只变文字来源,字号/颜色统一便于对比 -->
            <TextBlock Margin="0,16,0,6" FontSize="14" FontWeight="Bold" Foreground="#FF7FD1FF" Text="③ 文字 Text"/>
            <StackPanel Orientation="Horizontal" Margin="0,0,0,6">
                <TextBlock Width="150" FontSize="12" Foreground="#FF8C8C8C" VerticalAlignment="Center" Text="硬编码"/>
                <TextBlock FontSize="20" Foreground="#FFFFFFFF" VerticalAlignment="Center" Text="文字写死在 XAML 里"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal">
                <TextBlock Width="150" FontSize="12" Foreground="#FF8C8C8C" VerticalAlignment="Center" Text="可配置"/>
                <TextBlock FontSize="20" Foreground="#FFFFFFFF" VerticalAlignment="Center" Text="{DynamicResource ShadowLock.EffectText.ConfigText}"/>
            </StackPanel>

            <!-- ④ 渐变:同一个颜色声明,画刷属性引用 <Key>,Color 属性引用 <Key>.Color -->
            <TextBlock Margin="0,16,0,6" FontSize="14" FontWeight="Bold" Foreground="#FF7FD1FF" Text="④ 渐变 GradientStop"/>
            <StackPanel Orientation="Horizontal" Margin="0,0,0,6">
                <TextBlock Width="150" FontSize="12" Foreground="#FF8C8C8C" VerticalAlignment="Center" Text="硬编码"/>
                <Rectangle Height="20" RadiusX="4" RadiusY="4">
                    <Rectangle.Fill>
                        <LinearGradientBrush>
                            <GradientStop Offset="0" Color="#FF0078D4"/>
                            <GradientStop Offset="1" Color="#FFFFD700"/>
                        </LinearGradientBrush>
                    </Rectangle.Fill>
                </Rectangle>
            </StackPanel>
            <StackPanel Orientation="Horizontal">
                <TextBlock Width="150" FontSize="12" Foreground="#FF8C8C8C" VerticalAlignment="Center" Text="可配置(取颜色本身)"/>
                <Rectangle Height="20" RadiusX="4" RadiusY="4">
                    <Rectangle.Fill>
                        <LinearGradientBrush>
                            <GradientStop Offset="0" Color="{DynamicResource ShadowLock.EffectColor.ConfigColor.Color}"/>
                            <GradientStop Offset="1" Color="#FFFFD700"/>
                        </LinearGradientBrush>
                    </Rectangle.Fill>
                </Rectangle>
            </StackPanel>

            <!-- ⑤ 时间:只能走内置绑定,每秒刷新 -->
            <TextBlock Margin="0,16,0,6" FontSize="14" FontWeight="Bold" Foreground="#FF7FD1FF" Text="⑤ 时间 Binding"/>
            <StackPanel Orientation="Horizontal" Margin="0,0,0,6">
                <TextBlock Width="150" FontSize="12" Foreground="#FF8C8C8C" VerticalAlignment="Center" Text="写死"/>
                <TextBlock FontSize="20" Foreground="#FFFFFFFF" VerticalAlignment="Center" Text="12:00:00"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal">
                <TextBlock Width="150" FontSize="12" Foreground="#FF8C8C8C" VerticalAlignment="Center" Text="内置绑定(每秒刷新)"/>
                <TextBlock FontSize="20" Foreground="#FFFFFFFF" VerticalAlignment="Center" Text="{Binding time}"/>
                <TextBlock FontSize="20" Foreground="#FF9A9A9A" VerticalAlignment="Center" Margin="14,0,0,0" Text="{Binding dateChineseWeek}"/>
            </StackPanel>
        </StackPanel>
    </Border>
</Grid>
An unhandled error has occurred. Reload 🗙

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.