WPF 窗口淡入不起作用
我有以下代码:
<Window.Background>
<SolidColorBrush Opacity="0.7" Color="White" x:Name="BackgroundBrush"></SolidColorBrush>
</Window.Background>
<Window.Triggers>
<EventTrigger RoutedEvent="Loaded">
<EventTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:5" Storyboard.TargetName="BackgroundBrush" From="0.7">
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.EnterActions>
</EventTrigger>
</Window.Triggers>
但是显示窗口时没有任何反应。为什么?
I have the following code:
<Window.Background>
<SolidColorBrush Opacity="0.7" Color="White" x:Name="BackgroundBrush"></SolidColorBrush>
</Window.Background>
<Window.Triggers>
<EventTrigger RoutedEvent="Loaded">
<EventTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:5" Storyboard.TargetName="BackgroundBrush" From="0.7">
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.EnterActions>
</EventTrigger>
</Window.Triggers>
But nothing happened when window is shown. Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
AllowsTransparency
< /a> 为true
,这还需要WindowStyle
设置为None
。 (您需要创建自己的标准窗口按钮)AllowsTransparency
totrue
, which also necessitates theWindowStyle
to be set toNone
. (You need to create your own standard window buttons)除了 HB 所说的之外,您还需要将 BeginStoryboard 添加到 EventTrigger.Actions 集合,而不是 EnterActions 集合。所以这有效:
In addition to what H.B. said, you need to add your BeginStoryboard to the EventTrigger.Actions collection, not the EnterActions collection. So this works: