WPF 弹出窗口:用动画打开

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20069686/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 10:04:28  来源:igfitidea点击:

WPF Popup : open with animation

c#wpfxamlwpf-controls

提问by Priyank Thakkar

I am using a wpf popup control.

我正在使用 wpf 弹出控件。

<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.

我正在使用 .net 框架版本 3.5。

回答by Noctis

From MSDN

来自 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.

只有当 AllowsTransparency 属性设置为 true 时,Popup 才能设置动画。这需要创建 Popup 控件的应用程序以完全信任的方式运行。如果 PlacementTarget 已设置动画,则不会对 Popup 设置动画。

XAML should look like

XAML 应该看起来像

<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.

您可以在此处阅读更多内容。

回答by J R B

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

如果您已将 AllowsTransparency 设置为 true,则弹出窗口将具有动画效果。喜欢 -

AllowsTransparency="True".