Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在XAML中组合故事板?_Xaml_Storyboard_Visualstatemanager - Fatal编程技术网

如何在XAML中组合故事板?

如何在XAML中组合故事板?,xaml,storyboard,visualstatemanager,Xaml,Storyboard,Visualstatemanager,我正在寻找某种方法,将故事板组合到XAML中的其他故事板中 在下面的示例中,Thing1和Thing2是分别从顶部和底部滑动到画布上的两个文本块。我希望在任何时候只有一个、另一个或两者都不可见,因此我在VisualStateManager中设置了三个状态,在单个VisualStateGroup中,在各个状态之间进行转换 我希望能够在其他更简单的故事板的背景下,为Thing1Thothing2和Thing2Thothing1编写故事板。例如,有没有办法让故事板的内容1调用/调用/引用/由内容1 o

我正在寻找某种方法,将故事板组合到XAML中的其他故事板中

在下面的示例中,Thing1和Thing2是分别从顶部和底部滑动到画布上的两个文本块。我希望在任何时候只有一个、另一个或两者都不可见,因此我在VisualStateManager中设置了三个状态,在单个VisualStateGroup中,在各个状态之间进行转换

我希望能够在其他更简单的故事板的背景下,为Thing1Thothing2和Thing2Thothing1编写故事板。例如,有没有办法让故事板的内容1调用/调用/引用/由内容1 out和内容2 in组成?当然,代码可以复制,但是我们能做得更好吗?或者,有没有办法让视觉翻译做得更多

如果可能的话,我更愿意将它保存在XAML中,并且以一种可以扩展到更多事物的方式

谢谢! -大卫


<UserControl x:Class="WpfApplication1.UserControl1"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             Width="500" Height="500" Background="PaleTurquoise" >

    <UserControl.Resources>

        <Storyboard x:Key="Thing1In">
            <DoubleAnimation Storyboard.TargetName="Thing1" Storyboard.TargetProperty="(Canvas.Top)" Duration="0:0:2" To="100" />
        </Storyboard>

        <Storyboard x:Key="Thing1Out">
            <DoubleAnimation Storyboard.TargetName="Thing1" Storyboard.TargetProperty="(Canvas.Top)" Duration="0:0:2" To="-100" />
        </Storyboard>

        <Storyboard x:Key="Thing2In">
            <DoubleAnimation Storyboard.TargetName="Thing2" Storyboard.TargetProperty="(Canvas.Bottom)" Duration="0:0:2" To="100" />
        </Storyboard>

        <Storyboard x:Key="Thing2Out">
            <DoubleAnimation Storyboard.TargetName="Thing2" Storyboard.TargetProperty="(Canvas.Bottom)" Duration="0:0:2" To="-100" />
        </Storyboard>

        <Storyboard x:Key="Thing1ToThing2">
            <!--do Thing1Out then (or at the same time as) Thing2In-->
        </Storyboard>

        <Storyboard x:Key="Thing2ToThing1">
            <!--do Thing2Out then (or at the same time as) Thing1In-->
        </Storyboard>

    </UserControl.Resources>

    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="ThingStates">

            <VisualState x:Name="NothingInState" />
            <VisualState x:Name="Thing1InState" Storyboard="{StaticResource Thing1In}" />
            <VisualState x:Name="Thing2InState" Storyboard="{StaticResource Thing2In}" />

            <VisualStateGroup.Transitions>
                <VisualTransition From="Thing1InState" To="Thing2InState" Storyboard="{StaticResource Thing1ToThing2}" />
                <VisualTransition From="Thing2InState" To="Thing1InState" Storyboard="{StaticResource Thing2ToThing1}" />
                <VisualTransition From="Thing1InState" To="NothingInState" Storyboard="{StaticResource Thing1Out}" />
                <VisualTransition From="Thing2InState" To="NothingInState" Storyboard="{StaticResource Thing2Out}" />
            </VisualStateGroup.Transitions>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>

    <Canvas ClipToBounds="True">

        <TextBlock x:Name="Thing1" Text="Thing1" FontSize="60" Canvas.Top="-100" Canvas.Left="100" />

        <TextBlock x:Name="Thing2" Text="Thing2" FontSize="60" Canvas.Bottom="-100" Canvas.Left="100" />

    </Canvas>
</UserControl>