我想要一个从屏幕中间到直径大约 500 像素的圆圈。我将让这个圆圈充当我的应用程序的窗口(因此用户将像普通窗口一样拖动它)。
到目前为止,我可以让圆圈在启动时的动画中从 0 的高度和宽度增长到 500。它所在的窗口设置为透明且 SizeToContent ="WidthAndHeight"。这很好,因为包含窗口拥抱圆圈,但是圆圈不再从屏幕中心开始增长,它从中心开始向右侧和底部增长。
如何让圆在具有 SizeToContent="WidthAndHeight" 的同时从中心增长?
到目前为止,这是我的代码:
XAML
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
WindowStyle="None"
AllowsTransparency="True"
Background="Transparent"
WindowStartupLocation="CenterScreen"
SizeToContent="WidthAndHeight">
<Window.Resources>
<Storyboard x:Key="EllipseExpand">
<DoubleAnimation From="0" To="500" Duration="0:0:5"
Storyboard.TargetName="MyCircle"
Storyboard.TargetProperty="Width"/>
<DoubleAnimation From="0" To="500" Duration="0:0:5"
Storyboard.TargetName="MyCircle"
Storyboard.TargetProperty="Height"/>
</Storyboard>
</Window.Resources>
<Ellipse Name="MyCircle" Fill="Red" Height="0" Width="0"/>
</Window>
背后的代码
Imports System.Windows.Media.Animation
Class MainWindow
Public Sub WindowLoaded() Handles Me.Loaded
Dim ellipseExpand As Storyboard = FindResource("EllipseExpand")
ellipseExpand.Begin()
End Sub
End Class