[英]How to make an expanding form using WPF framework on visual studio?
So on the opening of my application I want it to go from a tiny little box to its normal size.所以在打开我的应用程序时,我希望它从一个小盒子变成 go 到它的正常大小。
Here is an example video: https://youtu.be/HIhuGGgRSuc这是一个示例视频: https://youtu.be/HIhuGGgRSuc
I'm new to wpf mainly the xaml part so im kinda stuck on what to do.我是 wpf 的新手,主要是 xaml 部分,所以我有点不知道该怎么做。
I have made a small sample using the story board.我使用故事板制作了一个小样本。 In XAML I did the following:
在 XAML 中,我做了以下操作:
Named my MainWindow and Grid.命名我的 MainWindow 和 Grid。
Set the following properties on my Main Window:在我的 Main Window 上设置以下属性:
Width and Height = Auto宽度和高度 = 自动
SizeToContent = WidthAndHeight SizeToContent = 宽度和高度
WindowStartUpLocation = CenterScreen WindowStartUpLocation = CenterScreen
WindowStyle = None窗口样式 = 无
Set the animation codes under Windows.Resources.在 Windows.Resources 下设置 animation 代码。
Here are the XAML codes:以下是 XAML 代码:
<Window x:Name="MainWin" x:Class="Window_Animation_Sample.MainWindow"
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"
mc:Ignorable="d"
Title="MainWindow" Width="Auto" Height="Auto" SizeToContent="WidthAndHeight" WindowStartupLocation="CenterScreen" WindowStyle="None">
<Window.Resources>
<Storyboard x:Key="ExpandingAnimation">
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="ExpandingGrid" Storyboard.TargetProperty="(FrameworkElement.Height)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="0"></EasingDoubleKeyFrame>
<EasingDoubleKeyFrame KeyTime="00:00:01" Value="0"></EasingDoubleKeyFrame>
<EasingDoubleKeyFrame KeyTime="00:00:05" Value="400"></EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Grid x:Name="ExpandingGrid">
<MediaElement Width="800" Height="400"/>
</Grid>
Here are the C# codes:以下是 C# 代码:
using System.Windows;
using System.Windows.Media.Animation;
namespace Window_Animation_Sample
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Storyboard ExpandingAnime = (Storyboard)TryFindResource("ExpandingAnimation");
ExpandingAnime.Begin();
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.