我有一个WPF窗口,其中包含一个ContentPresenter
,默认情况下Height和Width设置为0。
当用户点击一个按钮时,我会运行一个动画来将ContentPresenter的高度和宽度属性转换为896,1024(实际上它也会在其增长的同时进行3次旋转),这一切都很好......
User控件的DataContext实现了IDataErrorInfo,如果用户没有点击'我已阅读并理解这些健康&安全说明“复选框,然后复选框周围显示红色边框...
我的问题是,如果用户点击“取消”,我会运行缩小高度和高度的动画。宽度返回到0,0,然后UserControl根据需要缩小,但红色边框不会完全消失 - 它在我的窗口中间留下一个红色像素
任何人都有任何想法,我做错了什么? “红色边框”,我假设只是一个由WPF为我渲染的装配工,所以我不确定如何改变这种行为......
所有人都非常感谢!
更新 - 我尝试过Abe的优秀建议,但不幸的是它没有用,但确实让我尝试了其他的东西......所以现在我(暂时)评论了'缩小'动画,只需将可见性设置为在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>
谢谢,伊恩
答案 0 :(得分:1)
如果添加一个ObjectAnimationUsingKeyFrames,在其他动画完成时将元素的可见性设置为折叠,则装饰器也会消失。
<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执行反向操作。