当 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/