当两个情节提要设置不透明度属性时发生冲突?
背景:
我有一个 WPF UserControl(MainControl - 未在下面的代码中显示),其中包含另一个用户控件(在下面的代码中称为 MyControl)。
MainControl 将其 DataContext 设置为一个具有 Project 属性的对象。 当 MainControl 加载时,Project 属性始终为 null。
问题:
当MainControl加载时,我想使用特殊的故事板淡入MyControl(仅使用了一次(此“specialFadeInStoryboard”将MyControl的不透明度属性从0更改为1)。
当项目属性设置为 null 以外的值,我希望使用“fadeOutStoryboard”使 MyControl 淡出(将 MyControl 的不透明度属性更改为 0),如果之后将其设置为 null,我想这次再次淡入它使用“fadeInStoryboard”(将 MyControl 的不透明度属性更改为 1)。
但是,在添加“specialFadeInStoryboard”的代码后,MyControl 永远不会淡出......
我做错了什么?
<local:MyControl Visibility="{Binding RelativeSource={RelativeSource Self}, Path=Opacity, Converter={StaticResource opacityToVisibilityConverter}, Mode=OneWay}">
<local:MyControl.Style>
<Style>
<Style.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource specialFadeInStoryboard}"/>
</EventTrigger>
<DataTrigger Binding="{Binding Project, Converter={StaticResource nullToBooleanConverter}, Mode=OneWay}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource fadeOutStoryboard}"/>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource fadeInStoryboard}"/>
</DataTrigger.ExitActions>
</DataTrigger>
</Style.Triggers>
</Style>
</local:MyControl.Style>
</local:MyControl>
Background:
I have a WPF UserControl (MainControl - not shown in code below) that contains another one (called MyControl in the code below).
MainControl has it's DataContext set to an object, that has a Project-property.
When MainControl loads, the Project-property is always null.
The problem:
When MainControl loads, I want to fade in the MyControl using a special storyboard (only used this one time (this "specialFadeInStoryboard" changes Opacity-property of MyControl from 0 to 1).
When the Project-property is set to a value other than null, I want the MyControl to fade out using the "fadeOutStoryboard" (changes Opacity-property of MyControl to 0) and if it's set to null afterwards I want to fade it in again this time using the "fadeInStoryboard" (changes Opacity-property of MyControl to 1).
However, after adding the code for the "specialFadeInStoryboard", the MyControl is never faded out...
What am I doing wrong?
<local:MyControl Visibility="{Binding RelativeSource={RelativeSource Self}, Path=Opacity, Converter={StaticResource opacityToVisibilityConverter}, Mode=OneWay}">
<local:MyControl.Style>
<Style>
<Style.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource specialFadeInStoryboard}"/>
</EventTrigger>
<DataTrigger Binding="{Binding Project, Converter={StaticResource nullToBooleanConverter}, Mode=OneWay}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource fadeOutStoryboard}"/>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource fadeInStoryboard}"/>
</DataTrigger.ExitActions>
</DataTrigger>
</Style.Triggers>
</Style>
</local:MyControl.Style>
</local:MyControl>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能需要在其他淡入淡出故事板开始运行之前停止
specialFadeInStoryboard
。你可以用这样的东西来做到这一点:You might need to stop the
specialFadeInStoryboard
before the other fading storyboards begin running. You can do that with something like this: