在我上一個BLOG中寫到了滑動時不會觸發ListBoxItem,同樣接着上一個例子,我如果需要做一個分頁滑動的效果的話,首先要有滑動的效果,我覺得如果是分頁的話,那一個頁面中肯定是固定Item數目,然后在Canvas中放入3個一樣的ListBox分別把Canvas.left設置為你的窗口大小左右都放一個,中間放一個=-= 然后根據上個例子一樣往左拉都觸發動畫效果讓中間和右邊的Lis-tBox同時往左移動,最后再把動畫還原就可以了。這樣就可以實現拖動效果,然后Item里面的數據的話只要每次滑動的時候在中間的那個ListBox中變化就可以了(這個東西下次再寫)。
動畫的實現的話代碼如下:

Storyboard storyboard = new Storyboard(); DoubleAnimation doubleanimation = new DoubleAnimation(); doubleanimation.To = 0; doubleanimation.Duration = TimeSpan.FromSeconds(0.5); Storyboard.SetTarget(doubleanimation, listBox3); Storyboard.SetTargetProperty(doubleanimation, new PropertyPath("(Canvas.Left)")); storyboard.Children.Add(doubleanimation); storyboard.FillBehavior = FillBehavior.Stop; storyboard.Begin(); DoubleAnimation doubleAnimation = new DoubleAnimation(); doubleAnimation.To = 525; doubleAnimation.Duration = TimeSpan.FromSeconds(0.5); Storyboard.SetTarget(doubleAnimation, listBox1); Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("(Canvas.Left)")); storyboard.Children.Add(doubleAnimation); storyboard.FillBehavior = FillBehavior.Stop; storyboard.Begin();
雖然比較簡陋= =但是勉強能夠實現滑動效果~等下次學點高級的東西再改進吧。。。