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