不可以直接在styles.xaml里写storyboard吗?(进来就有分哈!!)

fanshaoer 2010-10-15 08:57:48
当layout加载时,我有一个控制背景渐变的storyboard。原来是直接在本地写的。如下。



<UserControl.Triggers>
<EventTrigger>
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="(StackPanel.Background).(GradientBrush.GradientStops)[0].(GradientStop.Color)">
<EasingColorKeyFrame KeyTime="00:00:03" Value="#FF80C0FF"/>
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="(StackPanel.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)">
<EasingColorKeyFrame KeyTime="00:00:03" Value="#FFEFFFFF"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</UserControl.Triggers>


因为每个page都要用到,我就把这个storyboard放到style.xaml里。如下

<UserControl
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" x:Class="Zthermo.AirTable" ……>
<Storyboard x:Name="LayoutRootAni">
<ColorAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="LayoutRoot"
Storyboard.TargetProperty="(StackPanel.Background).(GradientBrush.GradientStops)[0].(GradientStop.Color)">
<EasingColorKeyFrame KeyTime="00:00:03" Value="#FF80C0FF"/>
</ColorAnimationUsingKeyFrames>
<ColorAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="LayoutRoot"
Storyboard.TargetProperty="(StackPanel.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)">
<EasingColorKeyFrame KeyTime="00:00:03" Value="#FFEFFFFF"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>


然后,在原来的页面里的layout下这样调用。如下

<StackPanel x:Name="LayoutRoot" Loaded="LayoutRoot_Loaded" Style="{StaticResource SPBackStyle}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="LayoutRoot_Loaded">
<ei:ControlStoryboardAction Storyboard="{StaticResource LayoutRootAni}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
…………

不知道为什么不成功。。。把storyboard的name换成key也米用。。我是参考这个写的。
http://geekswithblogs.net/mbcrump/archive/2010/08/26/flashing-text-using-behaviorstoryboard-in-silverlight-4.aspx

谢谢!!!!!!!!进来就有分哈!!
...全文
113 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
fanshaoer 2010-10-18
  • 打赏
  • 举报
回复
没人知道么。。。
fanshaoer 2010-10-18
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 fanshaoer 的回复:]

XML code

[Quote=引用 7 楼 fanshaoer 的回复:]

XML code

<StackPanel x:Name="LayoutRoot" Loaded="LayoutRoot_Loaded"
Style="{StaticResource SPBackStyle}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<ei:ControlStoryboardAction Storyboard="{StaticResource LayoutRootAni}"/>
</i:EventTrigger>

[/Quote]代码给错了,应该是这个EventTrigger EventName="Loaded",而不是EventTrigger EventName="LayoutRoot_Loaded"
fanshaoer 2010-10-18
  • 打赏
  • 举报
回复

<StackPanel x:Name="LayoutRoot" Loaded="Loaded" Style="{StaticResource SPBackStyle}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="LayoutRoot_Loaded">
<ei:ControlStoryboardAction Storyboard="{StaticResource LayoutRootAni}"/>
</i:EventTrigger>
</i:Interaction.Triggers>



桔黄色的地方写错了吧,应该是事件名应该是loaded。。。我改完之后,出现clr错误,说Storyboard.TargetName="LayoutRoot" 无法找到
fanshaoer 2010-10-18
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 swt839 的回复:]

感觉楼主样式没调用到
[/Quote]确实没调用到。没任何反应
swt839 2010-10-18
  • 打赏
  • 举报
回复
感觉楼主样式没调用到
fanshaoer 2010-10-15
  • 打赏
  • 举报
回复
没有报错。。。就是动画没反应
passself 2010-10-15
  • 打赏
  • 举报
回复
楼主确定加载对了吗?报错是什么啊?根据报错来看看
fanshaoer 2010-10-15
  • 打赏
  • 举报
回复
大家还没睡醒哦。。。各位老大!!

8,735

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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