如何在 visual studio 上使用 WPF 框架制作扩展表单?

How to make an expanding form using WPF framework on visual studio?

所以在打开我的应用程序时,我希望它从一个小盒子变成正常大小。

这是一个示例视频: https://youtu.be/HIhuGGgRSuc

我是 wpf 的新手,主要是 xaml 部分,所以我有点不知道该怎么做。

我使用故事板制作了一个小样本。 在 XAML 中,我做了以下操作:

  1. 命名我的 MainWindow 和 Grid。

  2. 在我的 Main Window 上设置以下属性:

    • 宽度和高度 = 自动

    • SizeToContent = WidthAndHeight

    • WindowStartUpLocation = CenterScreen

    • Window风格=None

  3. 设置Windows.Resources下的动画代码。

这里是 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>

以下是 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();
        }
    }
}