3
为什么窗口代码中的以下事件无效?更改代码隐藏的不透明度
void about_Click(object sender, RoutedEventArgs e)
{
// TopLevel.Opacity = 1.0, Splashscreen.Opacity = 0.0
TopLevel.Opacity = 0.1;
// still: TopLevel.Opacity = 1.0
Splashscreen.Opacity = 1.0;
// still: Splashscreen.Opacity = 0.0
}
不透明度值不会改变。
我发现下面的触发是我的问题的原因:
<Window.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource splashscreenanimation}" />
</EventTrigger>
</Window.Triggers>
当我删除它的代码隐藏工作。
为了完整性,这是动画:
<Window.Resources>
<Storyboard x:Key="splashscreenanimation">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)"
Storyboard.TargetName="Splashscreen"
BeginTime="0:0:0.900">
<EasingDoubleKeyFrame KeyTime="0:0:1.5"
Value="0" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)"
Storyboard.TargetName="TopLevel"
BeginTime="0:0:0.900">
<EasingDoubleKeyFrame KeyTime="0:0:1.5"
Value="1" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
Solution:在后面的代码可以由第一执行移除动画:Splashscreen.BeginAnimation(UserControl.OpacityProperty, null);
(溅射屏幕是一个用户控件)。
我也尝试将FillBehavior="HoldEnd"
或FillBehavior="Stop"
添加到故事板,但没有让它正常工作。
我不同意你最近的评论......对我来说工作正常。也许你可以展示你的XAML的简化版本,它仍然表现出这种行为? – Sheridan