如何用Listbox实现轮动广告效果?

cpt_adt2010 2010-04-12 11:00:18
如何做listbox的轮动广告的动画呢,比如点下面的1-2-3-4-5导航键,产生图片切换,该动画的实现原理是什么呢。希望了解得说下动画实现原理,比如动画开始时XX属性值为XX,几分钟后XX属性值为XX等。
或者对下面的代码能够给些解释说明,谢谢大家
        <Storyboard x:Name="sbMove">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="lstImage" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
<EasingDoubleKeyFrame KeyTime="00:00:00.5000000" Value="-481" x:Name="kTo">
<EasingDoubleKeyFrame.EasingFunction>
<BackEase EasingMode="EaseInOut" Amplitude="0.5"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
</Storyboard>

            <ListBox x:Name="lstImage" Style="{StaticResource ListStyle}" ItemsPanel="{StaticResource HorizontalItemPanel}" ItemContainerStyle="{StaticResource ImageItemStyle}" ItemTemplate="{StaticResource ImageDataTemplate}" RenderTransformOrigin="0.5,0.5" Padding="0">
<ListBox.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</ListBox.RenderTransform>
</ListBox>

<ListBox Style="{StaticResource ListStyle}" ItemsPanel="{StaticResource HorizontalItemPanel}" ItemContainerStyle="{StaticResource NavItemStyle}" ItemTemplate="{StaticResource NavDataTemplate}" HorizontalAlignment="Right" VerticalAlignment="Bottom" x:Name="lstNav" />

        void MainPage_Loaded(object sender, RoutedEventArgs e)
{
string _ArremblyName = Assembly.GetExecutingAssembly().FullName.Split(',')[0];
_Items = new ObservableCollection<ImageItem>();

for (int i = 1; i <= 4; i++)
{
string _img = "http://images.24city.com/jimmy/ListBoxSlideShow/img/00" + i.ToString() + ".jpg";
_Items.Add(new ImageItem() { ImageUri = _img, Title = "这是图片00" + i.ToString() + ".jpg", ClickUri = _img, Index = i });
}

this.lstImage.ItemsSource = _Items;
this.lstNav.ItemsSource = _Items;
this.lstNav.SelectedIndex = _CurrentIndex;

_timer = new DispatcherTimer();
_timer.Interval = new System.TimeSpan(0, 0, 2);
_timer.Tick += new System.EventHandler(_timer_Tick);
_timer.Start();

}

void _timer_Tick(object sender, System.EventArgs e)
{
kTo.Value = _CurrentIndex * -480;
sbMove.Begin();
lstNav.SelectedIndex = _CurrentIndex;
_CurrentIndex++;
if (_CurrentIndex >= _Items.Count)
{
_CurrentIndex = 0;
}
}
...全文
168 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
cpt_adt2010 2010-04-15
  • 打赏
  • 举报
回复
求答案啊
jv9 2010-04-13
  • 打赏
  • 举报
回复
1. 首先项目使用StoryBoard关键帧动画,其中使用了EasingFunction(EasingInOut)效果,学习Easing参考:http://www.silverlightchina.net/html/learn/2010/0404/957.html
2. 该动画应用于目标控件Storyboard.TargetName="lstImage" ,而lstImage是ListBox
3. ListBox,lstNav是控件右下角数字导航的
4. 在项目中在静态资源中定义了模板和控件样式,你没有贴出来,但是你需要查看app.xaml或者style.xaml;
5. 在MainPage_Loaded中初始化控件和图片信息,绑定图片到lstImage,绑定图片的index到lstNav,另外设置定时器void _timer_Tick(object sender, System.EventArgs e),定时切换图片。

不知道这样解释你是否明白。
cpt_adt2010 2010-04-13
  • 打赏
  • 举报
回复
谢谢jv9,我想问一下,当点导航按钮(数字1,2,3)时,图片会产生向左或向右移动,并移出listbox,新图片向左或右移动进入listbox, 如何实现的呢
冰心的小屋 2010-04-12
  • 打赏
  • 举报
回复
挺经典的,支持楼主了
cpt_adt2010 2010-04-12
  • 打赏
  • 举报
回复
真强大,还未有答案,问题已经被搜索引擎收录了!才几个小时啊~

8,735

社区成员

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

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