WPF Popup : open with animation

2019-06-16 04:07发布

问题:

I am using a wpf popup control.

<Popup x:Name="tabHolder" IsOpen="False" 
    PopupAnimation="Slide" Placement="Bottom" 
    PlacementTarget="{Binding ElementName=mainWidgetWindow}">
    <Grid Height="105" Width="315" />
</Popup>

Here I have set popup animation property to slide. But when it opens, it doesn't animate. Do I have to add any other configuration for popup to open with animation option slide?

I am using .net framework version 3.5.

回答1:

From MSDN

A Popup can only animate when the AllowsTransparency property is set to true. This requires the application that creates the Popup control to run with full trust. If the PlacementTarget is animated, the Popup will not be animated.

XAML should look like

<DockPanel  Width="500" Background="Aqua">
  <Popup Placement="Center" PlacementRectangle="0,0,30,50"  
          IsOpen ="True" AllowsTransparency="True"
          PopupAnimation="Fade">
    <TextBlock Background="Purple">Popup Text</TextBlock>
  </Popup>
</DockPanel>

And you can read more here.



回答2:

Popup will animate if you have set AllowsTransparency true. like -

AllowsTransparency="True".