我一直在尝试用动画来打开一个UserControl,但没有成功,我想知道是否有人可以帮助我?
我有一个UserControl,它简单地保存了一条记录的信息。它打开作为一个框在现有的页面上,但我希望框打开一个简单的动画。我试图让盒子打开一个扩展的动画,而不是刚刚出现的盒子。
下面是我一直在编写的代码。
<UserControl Name="RecordViewerUserControl"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
x:Class="VisionWare.MasterDataServices.Silverlight.UI.Common.RecordViewer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
xmlns:conv="clr-namespace:VisionWare.MasterDataServices.Silverlight.UI.Converters"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
Height="490"
Width="600"
Margin="0,0,0,0">
<UserControl.Resources>
<conv:DateConverter x:Key="dateConverter" />
<conv:BoolToVisibilityConverter x:Key="visibilityConverter" />
<conv:EntityIdToUrlConverter x:Key="urlConverter"/>
<conv:FileConverter x:Key="fileConverter"/>
<conv:AlertImageURLConverter x:Key="alertConverter"/>
<Style TargetType="UserControl" x:Key="CustomUserControlStyle">
<Setter Property="Effect">
<Setter.Value>
<BeginStoryboard>
<Storyboard>
<DoubleAnimationUsingKeyFrames BeginTime="0" Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="(RenderTransform).(Children)[0].ScaleX">
<SplineDoubleKeyFrame KeyTime="00:00:00.2" Value="1" />
<SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="1.05" />
<SplineDoubleKeyFrame KeyTime="00:00:00.45" Value="0" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="0" Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="(RenderTransform).(Children)[0].ScaleY">
<SplineDoubleKeyFrame KeyTime="00:00:00.2" Value="1" />
<SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="1.05" />
<SplineDoubleKeyFrame KeyTime="00:00:00.45" Value="0" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>我已经根据@jrb的建议更改了代码...]
<UserControl.Triggers>
<EventTrigger RoutedEvent="UserControl.Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="RecordViewerUserControl" Storyboard.TargetProperty="Width" To="600"/>
<DoubleAnimation Storyboard.TargetName="RecordViewerUserControl" Storyboard.TargetProperty="Height" To="490"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</UserControl.Triggers>我在最初的UserControl开始标记后面插入了这段代码。当应用程序运行时,它不再抱怨,但是它似乎没有效果。
有什么想法吗?我是不是在后面的代码中遗漏了什么?
发布于 2011-11-29 18:46:07
我建议你测试一下将用户控件的大小设置为1,然后使用事件触发器加载(我想)和一个简单的双动画来增加控件的大小。
<EventTrigger RoutedEvent="Loaded">这是一个工作示例,您可以在kaxaml中测试它。
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="1"
Height="1"
Background="Black">
<Page.Triggers>
<EventTrigger RoutedEvent="Loaded">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetProperty="Width"
To="200"/>
<DoubleAnimation
Storyboard.TargetProperty="Height"
To="200"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Page.Triggers>
<Grid>
</Grid>
</Page>发布于 2011-11-29 18:47:53
我认为你的动画值是错误的,最终你的值应该是1 (100%大小)而不是0。
为什么要在LayoutRoot的第一个子对象上设置动画?您应该将RecordViewerUserControl作为动画目标。
https://stackoverflow.com/questions/8309357
复制相似问题