wpf - 当 Popup 的 IsOpen 属性设置为 True 时开始 StoryBoard

标签 wpf xaml animation triggers storyboard

当 Popup 的 IsOpen 属性设置为 True 时如何开始 StoryBoard?

例如:

<EventTrigger RoutedEvent="{Binding IsOpen, ElementName=pop}">
    <BeginStoryboard>
        <Storyboard>
            <DoubleAnimation Storyboard.TargetName="pop"
                             Storyboard.TargetProperty="Height"
                             Duration="0:0:1"
                             From="0.0"
                             To="200" />
            <DoubleAnimation Storyboard.TargetName="pop"
                             Storyboard.TargetProperty="Width"
                             Duration="0:0:1"
                             From="0.0"
                             To="{Binding ElementName=root,Path=ActualWidth}" />
        </Storyboard>
    </BeginStoryboard>
</EventTrigger>

我知道EventTrigger RoutedEvent="{Binding IsOpen, ElementName=pop} 不行

谢谢!

最佳答案

由于您没有标记“回答”,我认为您仍然需要一些帮助。 这是一个可以按照您的方式工作的代码片段(根据 H.B. 的帖子)

<Window x:Class="WpfTestApp.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Window.Resources>
    <Style x:Key="PopupStyle" TargetType="{x:Type Popup}">
        <Style.Triggers>
            <Trigger Property="IsOpen" Value="True">
                <Trigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation 
                                     Storyboard.TargetProperty="Height"
                                     Duration="0:0:1"
                                     From="0.0"
                                     To="200" />
                            <DoubleAnimation 
                                     Storyboard.TargetProperty="Width"
                                     Duration="0:0:1"
                                     From="0.0"
                                     To="500" />
                        </Storyboard>
                    </BeginStoryboard>
                </Trigger.EnterActions>
            </Trigger>
        </Style.Triggers> 

    </Style>
</Window.Resources>
<Grid>
    <Button Content="Button" Height="29" HorizontalAlignment="Left" Margin="24,19,0,0" Name="button1" VerticalAlignment="Top" Width="90" Click="button1_Click" />
    <Popup Name="pop" Style="{StaticResource PopupStyle}" >
        <Grid Background="Red">
            <TextBlock Text="I am in pop up" />
        </Grid>
    </Popup>
</Grid>

和按钮单击事件处理程序在代码后面打开弹出窗口..

 private void button1_Click(object sender, RoutedEventArgs e)
    {
        pop.PlacementTarget = (Button)sender;
        pop.IsOpen = true;
    }

关于wpf - 当 Popup 的 IsOpen 属性设置为 True 时开始 StoryBoard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6146342/

相关文章:

wpf - 如果RelativeSource不存在则隐藏DataTrigger

c# - 从大量声音文件中播放

触发器上的 WPF 样式边框厚度

ios - 使 CCSprite 在触摸时跟随另一个 CCSprite?

iphone - Cocos2D Director暂停/恢复问题

Javascript 彩色动画

wpf - 如何在代码中设置 FontFamily

wpf - Prism 4 WPF App - 实现了 MVVM、存储库和工作单元模式的解决方案架构

xaml - 使用Xamarin MVVM加载动态控件

wpf - 如何通过重新定义的列表框模板使用 UI 虚拟化