using System;
using System.Collections.ObjectModel;
using System.Reflection;
using System.Windows;
using System.Windows.Browser;
using System.Windows.Controls;
using System.Windows.Threading;
using System.Windows.Shapes;
namespace ListBoxSilde
{
public partial class MainPage : UserControl
{
ObservableCollection<ImageItem> _Items;
int _CurrentIndex = 0;//当前索引号(从0开始)
DispatcherTimer _timer;
public MainPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
}
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;
}
}
private void LayoutRoot_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
_timer.Stop();
}
private void LayoutRoot_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
_timer.Start();
}
private void Image_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
HtmlPage.Window.Navigate(new Uri(_Items[this.lstNav.SelectedIndex].ClickUri), "_target");
}
private void txtDebug_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
HtmlPage.Window.Navigate(new Uri("http://yjmyzz.cnblogs.com/"), "_target");
}
private void NavItemClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
StackPanel g = (sender as StackPanel);
TextBlock txt = g.Children[0] as TextBlock;
int Index = int.Parse(txt.Text);
kTo.Value = (Index - 1) * -480;
sbMove.Begin();
_CurrentIndex = Index - 1;
lstNav.SelectedIndex = _CurrentIndex;
}
}
public class ImageItem
{
public string ImageUri { set; get; }
public string Title { set; get; }
public string ClickUri { set; get; }
public int Index { set; get; }
}
}