我想知道如何使用 Xaml (WPF) 中的动画使文本块向上移动(或者更好地说是浮动)。
假设我有登录屏幕,并且有两个文本块:用户名和密码。当我点击文本块(用户名或密码)时,文本块会随着动画效果向上移动(浮动),直到文本块穿过框的边界线,然后文本块将停止移动。在同一个动画中,textblock中文字的字体大小变小(比如从12px到6px)。
另外,在同一个动画中,当文本向上移动时,我想为文本添加模糊效果,当文本块向上浮动时开始模糊效果,当文本块穿过框线时恢复正常。

最后,当我在登录屏幕上的其他地方单击时,如果框中没有写入任何内容,文本块将返回到起始点位置。
这是我的代码(不起作用)Xaml:
x:Class="tester.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:tester"
mc:Ignorable="d"
Title="Window1" Height="400" Width="600" >
<Grid>
<Border Margin="246,164,184,175" BorderThickness="1,1,1,1" BorderBrush="Black" >
<Label
Name="Two"
Margin="-1,-11,61,-1"
Width="100" Height="36" FontSize="20"
VerticalAlignment="Top" VerticalContentAlignment="Top"
Foreground="Blue" >
Name
<Label.Effect>
<BlurEffect Radius="0" x:Name="BlurEffect2"/>
</Label.Effect>
<Label.Triggers>
<EventTrigger
RoutedEvent="Label.MouseLeftButtonDown">
<BeginStoryboard>
<Storyboard x:Name="FirstLabelName" Completed="FirstLabelName_Completed" >
<DoubleAnimation
Storyboard.TargetName="Two"
Storyboard.TargetProperty="(Label.Height)"
To="20.0" Duration="0:0:0.3"
AutoReverse="False" />
<DoubleAnimation
Storyboard.TargetName="Two"
Storyboard.TargetProperty="(FontSize)"
To="16" Duration="0:0:0.3"
AutoReverse="False" />
<DoubleAnimation
Storyboard.TargetName="BlurEffect2"
Storyboard.TargetProperty="Radius"
To="10" Duration="0:0:0.3"
AutoReverse="False" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Label.Triggers> …Run Code Online (Sandbox Code Playgroud)