开始折叠的 VisualState 会干扰 WPF .NET 4 中的其他动画

发布于 2024-09-28 04:10:41 字数 3814 浏览 5 评论 0原文

我正在使用 .net 4、vs2010,并创建了一个用户控件,该控件需要开始折叠和透明(不透明度 0),并响应按钮单击而变得可见和不透明。

<UserControl x:Class="Ihi.LeadRetrieval.Client.Views.HelpView"
                     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                     xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
                     xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
                     mc:Ignorable="d" 
                     d:DesignHeight="300" d:DesignWidth="300">
<Grid x:Name="HelpGrid" Visibility="Collapsed" Opacity="0">
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="HelpStateGroup">
            <VisualStateGroup.Transitions>
                <VisualTransition GeneratedDuration="0:0:0.5">
                    <VisualTransition.GeneratedEasingFunction>
                        <CircleEase EasingMode="EaseInOut"/>
                    </VisualTransition.GeneratedEasingFunction>
                </VisualTransition>
            </VisualStateGroup.Transitions>
            <VisualState x:Name="HelpOpen">
            <Storyboard>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="HelpGrid">
                    <EasingDoubleKeyFrame KeyTime="0" Value="0.95"/>
                </DoubleAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="HelpGrid">
                    <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
                </ObjectAnimationUsingKeyFrames>
            </Storyboard>
            </VisualState>
            <VisualState x:Name="HelpClosed">
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <Border Background="#00427A" CornerRadius="3">
        <DockPanel Margin="5">
            <ContentPresenter DockPanel.Dock="Bottom" Margin="12,10,0,0" Content="{Binding Path=Detail}" Style="{StaticResource HelpText}"/>
            <Label Style="{StaticResource HelpHeaderText}" Content="{Binding Path=Header}" DockPanel.Dock="Left" MaxHeight="50"/>
            <Button x:Name="CloseHelpButton" Style="{StaticResource HelpButtonStyle}" Content="X" HorizontalAlignment="Right" VerticalAlignment="Top" DockPanel.Dock="Right" MaxHeight="50">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <ei:GoToStateAction x:Name="CloseAction" StateName="HelpClosed"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
        </DockPanel>
    </Border>
</Grid>

但是,当我从父用户控件定位此控件并触发 HelpOpen 视觉状态时,我注意到帮助控件在动画完成后突然出现 - 它不会按预期淡入。

<view:HelpView x:Name="helpView" />
<Button x:Name="ButtonOpen" Margin="0,0,25,0" VerticalAlignment="Top" Content="Open">
   <i:Interaction.Triggers>
        <i:EventTrigger EventName="Click">
            <ei:GoToStateAction TargetObject="{Binding ElementName=helpView}" StateName="HelpOpen"/>
        </i:EventTrigger>
   </i:Interaction.Triggers>
</Button>

我相信这是因为帮助控件仅在动画结束时才变得可见,因此不渲染增加不透明度的过渡。

有没有办法指定在调整不透明度值之前将可见性属性设置为可见?

I am using .net 4, vs2010 and have created a user control that needs to start collapsed and transparent (opacity 0) and become visible and opaque in response to a button click.

<UserControl x:Class="Ihi.LeadRetrieval.Client.Views.HelpView"
                     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                     xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
                     xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
                     mc:Ignorable="d" 
                     d:DesignHeight="300" d:DesignWidth="300">
<Grid x:Name="HelpGrid" Visibility="Collapsed" Opacity="0">
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="HelpStateGroup">
            <VisualStateGroup.Transitions>
                <VisualTransition GeneratedDuration="0:0:0.5">
                    <VisualTransition.GeneratedEasingFunction>
                        <CircleEase EasingMode="EaseInOut"/>
                    </VisualTransition.GeneratedEasingFunction>
                </VisualTransition>
            </VisualStateGroup.Transitions>
            <VisualState x:Name="HelpOpen">
            <Storyboard>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="HelpGrid">
                    <EasingDoubleKeyFrame KeyTime="0" Value="0.95"/>
                </DoubleAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="HelpGrid">
                    <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
                </ObjectAnimationUsingKeyFrames>
            </Storyboard>
            </VisualState>
            <VisualState x:Name="HelpClosed">
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <Border Background="#00427A" CornerRadius="3">
        <DockPanel Margin="5">
            <ContentPresenter DockPanel.Dock="Bottom" Margin="12,10,0,0" Content="{Binding Path=Detail}" Style="{StaticResource HelpText}"/>
            <Label Style="{StaticResource HelpHeaderText}" Content="{Binding Path=Header}" DockPanel.Dock="Left" MaxHeight="50"/>
            <Button x:Name="CloseHelpButton" Style="{StaticResource HelpButtonStyle}" Content="X" HorizontalAlignment="Right" VerticalAlignment="Top" DockPanel.Dock="Right" MaxHeight="50">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <ei:GoToStateAction x:Name="CloseAction" StateName="HelpClosed"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
        </DockPanel>
    </Border>
</Grid>

However, when I target this control from a parent user control and trigger the HelpOpen visual state, I notice that the help control is appears abruptely after the animation completes - it does not fade in as expected.

<view:HelpView x:Name="helpView" />
<Button x:Name="ButtonOpen" Margin="0,0,25,0" VerticalAlignment="Top" Content="Open">
   <i:Interaction.Triggers>
        <i:EventTrigger EventName="Click">
            <ei:GoToStateAction TargetObject="{Binding ElementName=helpView}" StateName="HelpOpen"/>
        </i:EventTrigger>
   </i:Interaction.Triggers>
</Button>

I believe this is because the help control is becoming visible only at the end of the animation and thus the transition of increasing opacity isn't rendered.

Is there a way to specify that the visibility property be set to visible before the opacity value is adjusted?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

不即不离 2024-10-05 04:10:41

我不确定您是否找到了问题的答案,但了解过渡和视觉状态是两个不同的时间线可能会有所帮助。

在混合中编辑过渡和状态是最简单的。事件顺序如下:

  1. 从状态 A 开始
  2. 某个触发器导致“转至状态”B
  3. 播放从状态 A 到 B 的转换(0.5 秒)。 转换中的不透明度或可见性没有变化。
  4. 状态 B 已应用/播放。这是不透明度和可见性更改的位置,并且由于状态 B 的持续时间为 0 秒,因此它们会立即发生

我通常做的是在混合中显式创建过渡(->stateB,stateA->< /em>,或状态A->状态B,等等)。然后,您可以调整何时应用可见性更改以及何时开始/结束不透明度更改。

I'm not sure if you found the answer to your question, but it might help to know that a transition and a visual state are two different timelines.

It is easiest to edit your transition and state in blend. The sequence of events is this:

  1. Begin in state A
  2. Some trigger causes a "Go to state" B
  3. The transition from state A to B plays (0.5 seconds). There are no changes to opacity or visibility in your transition
  4. The state B is applied/played. Here is where your opacity and visibility changes are, and since state B has a duration of 0 seconds, they occur immediately

What I usually do is explicitly create the transition in blend (either ->stateB, stateA->, or stateA->stateB, etc). Then you can adjust when the visibility change is applied and when the opacity change begins/ends.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文