C# 如何在不打开新窗口的情况下切换窗口?

C# 如何在不打开新窗口的情况下切换窗口?,c#,wpf,xaml,C#,Wpf,Xaml,我用xaml创建了一个动画,我想在一个新窗口中播放第二部分。我当然可以在登录动画完成后打开一个新窗口并播放它,但我想知道是否可以保持在同一个窗口中,但使用不同的xaml文件 <Window x:Class="TestWpfAnimation1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/w

我用xaml创建了一个动画,我想在一个新窗口中播放第二部分。我当然可以在登录动画完成后打开一个新窗口并播放它,但我想知道是否可以保持在同一个窗口中,但使用不同的xaml文件

<Window x:Class="TestWpfAnimation1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="600" Width="1000"
    WindowStartupLocation="CenterScreen">
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>
    <StackPanel Grid.Row="1"
                Grid.ColumnSpan="2"
                VerticalAlignment="Center"
                HorizontalAlignment="Center">
        <StackPanel x:Name="StackPanelName"
                    Orientation="Horizontal"
                    HorizontalAlignment="Left"
                    VerticalAlignment="Center">
            <StackPanel.RenderTransform>
                <TranslateTransform X="0" />
            </StackPanel.RenderTransform>
            <Label Content="_Name:"
                   Target="{Binding ElementName=TextBoxName}" />
            <TextBox Height="19"
                     Width="110"
                     Margin="18.55,0,0,0" />
        </StackPanel>
        <StackPanel x:Name="StackPanelPassword"
                    Orientation="Horizontal"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center">
            <StackPanel.RenderTransform>
                <TranslateTransform />
            </StackPanel.RenderTransform>
            <Label Content="_Password:" />
            <PasswordBox Height="19"
                         Width="110" />
        </StackPanel>
        <Button
            Content="Log in"
            HorizontalAlignment="Center"
            VerticalAlignment="Bottom"
            Width="60"
            IsDefault="True"
            Margin="0,13,0,0"
            Grid.Row="1"
            Grid.ColumnSpan="2">
            <Button.Triggers>
                <EventTrigger RoutedEvent="Button.Click">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity">
                                <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0" />
                            </DoubleAnimationUsingKeyFrames>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="StackPanelName"
                                                           Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)">
                                <EasingDoubleKeyFrame KeyTime="0:0:0.5"
                                                      Value="0" />
                                <EasingDoubleKeyFrame KeyTime="0:0:1.5"
                                                      Value="-381" />
                            </DoubleAnimationUsingKeyFrames>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="StackPanelName"
                                                           Storyboard.TargetProperty="Opacity">
                                <EasingDoubleKeyFrame KeyTime="0:0:0.5"
                                                      Value="1" />
                                <EasingDoubleKeyFrame KeyTime="0:0:1.5"
                                                      Value="0" />
                            </DoubleAnimationUsingKeyFrames>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="StackPanelPassword"
                                                           Storyboard.TargetProperty="RenderTransform.(TranslateTransform.X)">
                                <EasingDoubleKeyFrame KeyTime="0:0:0.5"
                                                      Value="0" />
                                <EasingDoubleKeyFrame KeyTime="0:0:1.5"
                                                      Value="381" />
                            </DoubleAnimationUsingKeyFrames>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="StackPanelPassword"
                                                           Storyboard.TargetProperty="Opacity">
                                <EasingDoubleKeyFrame KeyTime="0:0:0.5"
                                                      Value="1" />
                                <EasingDoubleKeyFrame KeyTime="0:0:1.5"
                                                      Value="0" />
                            </DoubleAnimationUsingKeyFrames>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="ImageProfilePicture"
                                                           Storyboard.TargetProperty="Opacity">
                                <EasingDoubleKeyFrame KeyTime="0:0:1.5"
                                                      Value="0"/>
                                <EasingDoubleKeyFrame KeyTime="0:0:2"
                                                      Value="1"/>
                            </DoubleAnimationUsingKeyFrames>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="StackPanelNameTitle"
                                                           Storyboard.TargetProperty="Opacity">
                                <EasingDoubleKeyFrame KeyTime="0:0:2"
                                                      Value="0" />
                                <EasingDoubleKeyFrame KeyTime="0:0:3"
                                                      Value="1" />
                            </DoubleAnimationUsingKeyFrames>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Button.Triggers>
        </Button>
    </StackPanel>
    <StackPanel Orientation="Horizontal"
                HorizontalAlignment="Left"
                VerticalAlignment="Top">
        <Rectangle x:Name="ImageProfilePicture"
                   Fill="Black"
                   Height="50"
                   Width="50"
                   HorizontalAlignment="Left"
                   Margin="10,10,0,0" 
                   Opacity="0"/>
        <StackPanel x:Name="StackPanelNameTitle"
                    VerticalAlignment="Center"
                    Opacity="0">
            <TextBlock Text="First Last name"
                       Margin="8,0,0,0"
                       FontSize="13"
                       FontWeight="SemiBold"/>
            <TextBlock Text="Student"
                       HorizontalAlignment="Center"/>
        </StackPanel>
    </StackPanel>
</Grid>


为什么不仅仅是一个UserControl?或者?如果第二个页面/窗口应该返回一个值,那么PageFunction也适用。有关示例,请访问。考虑到您不想使用新窗口,您是否需要使用新窗口?感谢您的建议,在动画完成的eventhandler中,我将窗口的内容设置为新页面,并在新文件中播放了第二部分。谢谢你的建议。第二个页面应该是某种仪表板,所以我认为它应该与登录内容分开。你可以在一个框架中托管一个页面。我做了很多事情来发布内容。页面将驻留在框架中,但窗口不会。但是页面很像一个窗口。