0

我有一个 WPF 窗口,其中包含ContentPresenter默认情况下高度和宽度设置为 0 的 WPF 窗口。当用户单击一个按钮时,我运行一个动画将 ContentPresenter 的高度和宽度属性转换为 896,1024(实际上它在增长的同时也进行了 3 次旋转),这一切都很好......

用户控件的 DataContext 实现了 IDataErrorInfo,如果用户没有单击“我已阅读并理解这些健康和安全说明”复选框,则复选框周围会显示一个红色边框...

我的问题是,如果用户单击“取消”,并且我运行将高度和宽度缩小回 0,0 的动画,则 UserControl 会根据需要缩小,但红色边框不会完全消失 - 它只留下一个我的窗口中间的红色像素

有人知道我做错了什么吗?我假设“红色边框”只是 WPF 为我呈现的装饰器,所以我不知道如何改变这种行为......

非常感谢所有帮助!

更新- 我尝试了 Abe 的极好建议,但不幸的是它没有用,但它确实让我尝试了其他东西......所以现在我(暂时)注释掉了“缩小”动画,并简单地将可见性设置为 Collapsed at KeyTime="0:0:0.9" ... 当我按下取消键时,不到一秒钟后,UserControl 消失了,但红色的装饰物顽固地保留着:(

作为额外的信息(不确定是否相关?)在 ContentPresenter 中显示的 UserControl 还包含一个 ContentPresenter 来呈现 UserControl,其内部内容包含验证装饰器......

代码示例:

<Button
    Name="signInButton"
    Grid.Row="0" Grid.Column="0"
    Margin="30"
    HorizontalAlignment="Right" VerticalAlignment="Bottom"
    Style="{StaticResource LargeButtonStyle}" 
    Content="Sign In"
    Command="{Binding SignInCommand}">
    <Button.Triggers>
        <EventTrigger
            RoutedEvent="Button.Click">
            <BeginStoryboard
                Storyboard="{DynamicResource openViewAnimation}" />
        </EventTrigger>
    </Button.Triggers>
</Button>

<ContentPresenter
    Name="mainView"
    Grid.RowSpan="2" Grid.ColumnSpan="2"
    HorizontalAlignment="Center" VerticalAlignment="Center"
    Opacity="0.9"
    Content="{Binding CurrentContent}">
    <ContentPresenter.RenderTransform>
        <RotateTransform
            Angle="0" />
    </ContentPresenter.RenderTransform>
</ContentPresenter>

<Storyboard x:Key="closeViewAnimation">
    <DoubleAnimation
        Storyboard.TargetName="mainView" Storyboard.TargetProperty="Height"
        From="896" To="0" Duration="0:0:0.9"
        AutoReverse="False" RepeatBehavior="1x" />
    <DoubleAnimation
        Storyboard.TargetName="mainView" Storyboard.TargetProperty="Width"
        From="1024" To="0" Duration="0:0:0.9"
        AutoReverse="False" RepeatBehavior="1x" />
</Storyboard>

谢谢,伊恩

4

1 回答 1

1

如果您添加一个 ObjectAnimationUsingKeyFrames,在其他动画完成时将元素的 Visibility 设置为 Collapsed,则装饰器也会消失。

<Storyboard x:Key="closeViewAnimation">
    <DoubleAnimation
        Storyboard.TargetName="mainView" Storyboard.TargetProperty="Height"
        From="896" To="0" Duration="0:0:0.9"
        AutoReverse="False" RepeatBehavior="1x" />
    <DoubleAnimation
        Storyboard.TargetName="mainView" Storyboard.TargetProperty="Width"
        From="1024" To="0" Duration="0:0:0.9"
        AutoReverse="False" RepeatBehavior="1x" />
    <ObjectAnimationUsingKeyFrames 
        Storyboard.TargetName="mainView"
        Storyboard.TargetProperty="Visibility">
        <DiscreteObjectKeyFrame Value="{x:Static Visibility.Collapsed}" 
            KeyTime="0:0:0.9" />
    </ObjectAnimationUsingKeyFrames>
</Storyboard>

显然,您需要在 KeyTime 0 处为 openViewAnimation 执行反向操作。

于 2010-03-03T21:57:01.697 回答