WPF动画:在网格单元移动图像 [英] WPF Animation: Moving images in Grid cells

查看:201
本文介绍了WPF动画:在网格单元移动图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是WPF的初学者,我已经在网格中显示一个数组的图像,再有就是这个按钮,左,右,所以我按一下左边的时候我会在图像向左移动显示另一组从阵列图像。同样也与右按钮图像向右移动。其www.yahoo.com主页像浏览当天的头条新闻时。如何能在WPF做呢?谢谢!

I'm a beginner of WPF, I have a an array images to be displayed in the grid, then there is this button, left and right, so that when I click left I will move the images to the left to display another set of images from the array. Same also with the right button to move the images to the right. Its like in www.yahoo.com main page when browsing the top news of the day. How can that be done in WPF? Thanks!

推荐答案

您可以做到这一点使用ItemsControl的和不断变化的按钮点击物品的来源...

You can do that using itemscontrol and changing the source of items on button click...

看看下面这个示例中我正在物品样​​本与数据模板的StackPanel作为itemshost ...和图像控制....

look at the sample below in this sample i am taking a items control with stackpanel as itemshost... and image in data template....

在左边或右边点击按钮可以改变的ItemsControl的ItemsSource的...

on click of left or right button you can change the itemssource of the itemscontrol...

  <ItemsControl ItemsSource="{Binding Images}" >
                                            <ItemsControl.ItemTemplate>
                                                <DataTemplate>
                                                    <Image Source={Binding}></Image>
                                                </DataTemplate>
                                            </ItemsControl.ItemTemplate>
                                            <ItemsControl.ItemsPanel>
                                                <ItemsPanelTemplate>
                                                    <Stackpanle Orientation="Horizontal" IsItemsHost="True" />
                                                </ItemsPanelTemplate>
                                            </ItemsControl.ItemsPanel>
                                        </ItemsControl>

编辑:
改变数据的上下文,然后才能动画的ItemsControl和更改的datacontext,并把它..

Before changing the data context you can animate the itemscontrol and change the datacontext and bring it in..

这篇关于WPF动画:在网格单元移动图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆