当两个情节提要设置不透明度属性时发生冲突?

发布于 2024-08-29 00:35:56 字数 1794 浏览 4 评论 0原文

背景

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

女皇必胜 2024-09-05 00:35:56

您可能需要在其他淡入淡出故事板开始运行之前停止 specialFadeInStoryboard。你可以用这样的东西来做到这一点:

<DataTrigger.EnterActions>
    <StopStoryboard BeginStoryboardName="specialFadeInStoryboard"/>
    <BeginStoryboard Storyboard="{StaticResource fadeOutStoryboard}"/>
</DataTrigger.EnterActions>

You might need to stop the specialFadeInStoryboard before the other fading storyboards begin running. You can do that with something like this:

<DataTrigger.EnterActions>
    <StopStoryboard BeginStoryboardName="specialFadeInStoryboard"/>
    <BeginStoryboard Storyboard="{StaticResource fadeOutStoryboard}"/>
</DataTrigger.EnterActions>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文