.net Silverlight缩略图水平旋转木马?
更新: 我找到了这个解决方案。。。修改了它,但我很难让它做一个连续的循环(列表/数组中的第一项弹出到最后一项) 非常感谢您的帮助.net Silverlight缩略图水平旋转木马?,.net,silverlight,xaml,.net,Silverlight,Xaml,更新: 我找到了这个解决方案。。。修改了它,但我很难让它做一个连续的循环(列表/数组中的第一项弹出到最后一项) 非常感谢您的帮助 using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Wi
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.Windows.Media.Imaging;
using System.Windows.Browser;
/*
* A Image Carousel Demonstratoin in C#
* from shinedraw.com
*/
namespace ImageCarousel
{
public partial class ImageCarousel : UserControl
{
private String[] IMAGES = { "images/image1.png", "images/image2.png", "images/image3.png", "images/image4.png", "images/image5.png", "images/image6.png", "images/image7.png", "images/image8.png", "images/image9.png"}; // images
private static double IMAGE_WIDTH = 128; // Image Width
private static double IMAGE_HEIGHT = 128; // Image Height
private static double SPRINESS = 0.4; // Control the Spring Speed
private static double DECAY = 0.5; // Control the bounce Speed
private static double SCALE_DOWN_FACTOR = 0.05; // Scale between images
private static double OFFSET_FACTOR = 50; // Distance between images
private static double OPACITY_DOWN_FACTOR = 0.1; // Alpha between images
private static double MAX_SCALE = 1; // Maximum Scale
private double _xCenter;
private double _yCenter;
private double _target = 0; // Target moving position
private double _current = 0; // Current position
private double _spring = 0; // Temp used to store last moving
private List<Image> _images = new List<Image>(); // Store the added images
private static int FPS = 24; // fps of the on enter frame event
private DispatcherTimer _timer = new DispatcherTimer(); // on enter frame simulator
public ImageCarousel()
{
InitializeComponent();
// Save the center position
//_xCenter = Width / 2;
//_yCenter = Height / 2;
_xCenter = 0;
_yCenter = Height / 2;
addImages();
// add the click handler
this.MouseLeftButtonDown += new MouseButtonEventHandler(ImageNaigation_MouseLeftButtonDown);
// add the scroll handler
HtmlPage.Window.AttachEvent("DOMMouseScroll", OnMouseWheel);
HtmlPage.Window.AttachEvent("onmousewheel", OnMouseWheel);
HtmlPage.Document.AttachEvent("onmousewheel", OnMouseWheel);
}
/////////////////////////////////////////////////////
// Handlers
/////////////////////////////////////////////////////
// reposition the images
void _timer_Tick(object sender, EventArgs e)
{
for(int i = 0; i < _images.Count; i++){
Image image = _images[i];
posImage(image, i);
}
// compute the current position
// added spring effect
_spring = (_target - _current) * SPRINESS + _spring * DECAY;
_current += _spring;
}
// define the new target by mouse wheel
private void OnMouseWheel(object sender, HtmlEventArgs args)
{
double mouseDelta = 0;
ScriptObject e = args.EventObject;
// Mozilla and Safari
if (e.GetProperty("detail") != null)
{
mouseDelta = ((double)e.GetProperty("detail"));
}
// IE and Opera
else if (e.GetProperty("wheelDelta") != null)
mouseDelta = ((double)e.GetProperty("wheelDelta"));
mouseDelta = Math.Sign(mouseDelta);
moveIndex((mouseDelta > 0) ? 1 : -1);
}
// define the new target by mouse click (Forward position only)
void ImageNaigation_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
moveIndex(1);
}
/////////////////////////////////////////////////////
// Private Methods
/////////////////////////////////////////////////////
// add images to the stage
private void addImages(){
for(int i = 0; i < IMAGES.Length; i++){
// get the image resources from the xap
string url = IMAGES[i];
Image image = new Image();
image.Source = new BitmapImage(new Uri(url, UriKind.Relative));
// add and reposition the image
LayoutRoot.Children.Add(image);
posImage(image, i);
_images.Add(image);
}
}
// move the index
private void moveIndex(int value)
{
_target += value;
_target = Math.Max(0, _target);
_target = Math.Min(_images.Count - 1, _target);
}
// reposition the image
private void posImage(Image image , int index){
double diffFactor = index - _current;
double left = _xCenter + ((IMAGE_WIDTH + OFFSET_FACTOR) * diffFactor);
double top = _yCenter;
image.SetValue(Canvas.LeftProperty, left);
image.SetValue(Canvas.TopProperty, top);
}
/////////////////////////////////////////////////////
// Public Methods
/////////////////////////////////////////////////////
// start the timer
public void Start()
{
// start the enter frame event
_timer = new DispatcherTime`enter code here`r();
_timer.Interval = new TimeSpan(0, 0, 0, 0, 1000 / FPS);
_timer.Tick += new EventHandler(_timer_Tick);
_timer.Start();
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
Net系统;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Animation;
使用System.Windows.Shapes;
使用System.Windows.Threading;
使用System.Windows.Media.Imaging;
使用System.Windows.Browser;
/*
*用C语言演示的图像旋转木马#
*来自shinedraw.com
*/
名称空间图像转盘
{
公共部分类ImageCarousel:UserControl
{
私有字符串[]IMAGES={“IMAGES/image1.png”、“IMAGES/image2.png”、“IMAGES/image3.png”、“IMAGES/image4.png”、“IMAGES/image5.png”、“IMAGES/image6.png”、“IMAGES/image7.png”、“IMAGES/image8.png”、“IMAGES/image9.png”};//IMAGES
私有静态双映像_WIDTH=128;//映像宽度
私有静态双映像_HEIGHT=128;//映像高度
私有静态双弹簧=0.4;//控制弹簧速度
私有静态双衰减=0.5;//控制反弹速度
私有静态双比例系数=0.05;//图像之间的比例
私有静态双偏移_因子=50;//图像之间的距离
私有静态双不透明度系数=0.1;//图像之间的Alpha
专用静态双最大刻度=1;//最大刻度
私人双中心;
私人双中心;
私有双_target=0;//目标移动位置
专用双精度_current=0;//当前位置
private double _spring=0;//用于存储上次移动的临时值
私有列表_images=new List();//存储添加的图像
私有静态int FPS=24;//输入帧事件的FPS
私有调度程序_timer=new dispatchermer();//输入帧模拟器
公共图像传送带()
{
初始化组件();
//保存中心位置
//_xCenter=宽度/2;
//_中心=高度/2;
_xCenter=0;
_中心=高度/2;
addImages();
//添加单击处理程序
this.MouseLeftButtonDown+=新的MouseButtonEventHandler(ImageNaigation\u MouseLeftButtonDown);
//添加滚动处理程序
HtmlPage.Window.AttachEvent(“DOMMouseScroll”,onmouseheel);
HtmlPage.Window.AttachEvent(“onmouseheel”,onmouseheel);
HtmlPage.Document.AttachEvent(“onmouseheel”,onmouseheel);
}
/////////////////////////////////////////////////////
//处理者
/////////////////////////////////////////////////////
//重新定位图像
void\u timer\u Tick(对象发送方,事件参数e)
{
对于(int i=0;i<\u images.Count;i++){
图像图像=_图像[i];
posImage(image,i);
}
//计算当前位置
//附加弹簧效应
_弹簧=(_目标-_当前)*弹簧+_弹簧*衰减;
_电流+=\U弹簧;
}
//通过鼠标滚轮定义新目标
MouseWheel上的私有void(对象发送器、HtmlEventArgs参数)
{
双鼠标delta=0;
ScriptObject e=args.EventObject;
//Mozilla和Safari
如果(例如GetProperty(“详细信息”)!=null)
{
mouseDelta=((双精度)e.GetProperty(“细节”);
}
//音乐与歌剧
else if(e.GetProperty(“wheelDelta”)!=null)
mouseDelta=((双精度)e.GetProperty(“wheelDelta”);
mouseDelta=数学符号(mouseDelta);
移动索引((mouseDelta>0)?1:-1);
}
//通过鼠标单击定义新目标(仅限前进位置)
void ImageNaigation_MouseLeftButtonDown(对象发送器,MouseButtonEventArgs e)
{
移动索引(1);
}
/////////////////////////////////////////////////////
//私有方法
/////////////////////////////////////////////////////
//在舞台上添加图像
私有void addImages(){
对于(int i=0;i
您的列表中有多少项
一个非常简单的方法是在页面上有一个列表框,比如说宽度为600px。然后将其包装在一个画布中,该画布的clipToBounds属性设置为true,宽度设置为小于列表框,例如300px
然后在画布的左侧和右侧添加按钮,然后