请教wpf 动画触发的问题

bossaiaboy 2016-02-03 01:03:53
是这样的,我做了一个控件,控件加了一些动画效果;在程序启动的时候,原意是把图片和文字信息加载上去后,再触发动画,但是现在是先会不带资源的触发一次动画,接着再加载图片资源;
代码如下:

<UserControl x:Class="MyWard.MyUserControl.ChangeImage"
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"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
<Storyboard x:Key="Storyboard1">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="myImage">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:8" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:10" Value="0"/>
</DoubleAnimationUsingKeyFrames>

<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="myImage">
<EasingDoubleKeyFrame KeyTime="0" Value="280"/>
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="1.5"/>
<EasingDoubleKeyFrame KeyTime="0:0:8" Value="-1.625"/>
<EasingDoubleKeyFrame KeyTime="0:0:10" Value="-304"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="myImage">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="2.833"/>
<EasingDoubleKeyFrame KeyTime="0:0:8" Value="0.708"/>
<EasingDoubleKeyFrame KeyTime="0:0:10" Value="4"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="grid">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:8" Value="1"/>
<EasingDoubleKeyFrame KeyTime="0:0:10" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</UserControl.Resources>
<UserControl.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">在这个地方怎么去修改RoutedEvient改成自定义的呢?
<BeginStoryboard x:Name="Storyboard1_BeginStoryboard" Storyboard="{StaticResource Storyboard1}"/>
</EventTrigger>
</UserControl.Triggers>
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="133*"/>
<RowDefinition Height="17*"/>
</Grid.RowDefinitions>
<Image x:Name="myImage" Grid.RowSpan="2" Source="{Binding ImageSource,UpdateSourceTrigger=PropertyChanged}" Margin="20" RenderTransformOrigin="0.5,0.5" >
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Image.RenderTransform>
</Image>
<Grid x:Name="grid" Grid.Row="1" RenderTransformOrigin="0.5,0.5">
<Grid.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Grid.RenderTransform>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="1.5*"/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="1">
<TextBlock Text="{Binding GameMoney,UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Right" FontSize="25" Foreground="Orange"></TextBlock>
</Grid>
<Grid Grid.Column="2">
<Image Source="/MyWard;component/Images/money.png" VerticalAlignment="Top" HorizontalAlignment="Left"></Image>
</Grid>
<!--<TextBlock Text="游戏价格:2元/次" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>-->
</Grid>
<!--<Border x:Name="border" BorderBrush="#FF15894F" Grid.RowSpan="2" BorderThickness="5" HorizontalAlignment="Left" Height="300" Margin="0,0,-1,0" VerticalAlignment="Top" Width="301" d:IsHidden="True"/>-->
</Grid>
</UserControl>
...全文
163 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xinweilee 2016-02-03
  • 打赏
  • 举报
回复
引用 3 楼 xinweilee 的回复:
要添加命名空间 <UserControl x:Class="MyWard.MyUserControl.ChangeImage" 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:local="clr-namespace:MyWard.MyUserControl.ChangeImage" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> 然后MyroutEvent这样写"MyWard.MyUserControl.ChangeImage.MyroutEvent"
错了,应该写成"local:ChangeImage.MyroutEvent"
xinweilee 2016-02-03
  • 打赏
  • 举报
回复
要添加命名空间 <UserControl x:Class="MyWard.MyUserControl.ChangeImage" 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:local="clr-namespace:MyWard.MyUserControl.ChangeImage" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> 然后MyroutEvent这样写"MyWard.MyUserControl.ChangeImage.MyroutEvent"
bossaiaboy 2016-02-03
  • 打赏
  • 举报
回复
引用 1 楼 xinweilee 的回复:
ChangeImage控件里自定义RouteEvent,将EventTrigger中的RouteEvent替换成自定义的路由事件,同时控制一下触发自定义事件的触发时机就行了。
比如说我定义了一个路由事件,如下:

public static readonly RoutedEvent MyroutEvent = EventManager.RegisterRoutedEvent("BeginAnimation",
            RoutingStrategy.Bubble, typeof (RoutedEventHandler), typeof (ChangeImage));
        public event RoutedEventHandler BeginAnimation
        {
            add { this.AddHandler(MyroutEvent, value); }
            remove { this.RemoveHandler(MyroutEvent,value); }
        }
但是在xaml中的 <EventTrigger RoutedEvent="FrameworkElement.Loaded">改成MyroutEvent时,提示无法访问或者识别MyroutEvent,还是说我改变的方式不对呢?求指点
xinweilee 2016-02-03
  • 打赏
  • 举报
回复
ChangeImage控件里自定义RouteEvent,将EventTrigger中的RouteEvent替换成自定义的路由事件,同时控制一下触发自定义事件的触发时机就行了。

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧