Begin a StoryBoard when IsOpen property of a Popup is set to True
How to Begin a StoryBoard when IsOpen property of a Popup is set to True?
ex:
<EventTrigger RoutedEvent="{Binding IsOpen, ElementName=pop}">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="pop"
Storyboard.TargetProperty="Height"
Duration="0:0:1"
From="0.0"
To="20开发者_如何学运维0" />
<DoubleAnimation Storyboard.TargetName="pop"
Storyboard.TargetProperty="Width"
Duration="0:0:1"
From="0.0"
To="{Binding ElementName=root,Path=ActualWidth}" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
I know EventTrigger RoutedEvent="{Binding IsOpen, ElementName=pop}
is not ok
Thank you!
Since you did not mark for Answer, I assumed you still need some help in this. Here is a code snippet that will work your way (as per H.B.'s post)
<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>
and the button click event handler in code behind to open the pop up..
private void button1_Click(object sender, RoutedEventArgs e)
{
pop.PlacementTarget = (Button)sender;
pop.IsOpen = true;
}
- Create a
Style
for the Popup. Trigger
onIsOpen
->true
- Use
Trigger.EnterActions
to start a storyboard.
精彩评论