写在wp8.1的filpview马上来临之际

移动开发
大家肯定熟悉安卓各种客户端首页联动图片广告(比如淘宝),可以自动滚动,可以手动滑动,当然是循环的。但是在wp上我看到的做的最好的最早的当属爱壁纸了。

一直想写点东西,直到今天才真正动笔,唯一的原因就是太懒,太懒...

大家肯定熟悉安卓各种客户端首页联动图片广告(比如淘宝),可以自动滚动,可以手动滑动,当然是循环的。但是在wp上我看到的做的***的最早的当属爱壁纸了。

写在wp8.1的filpview马上来临之际。上代码吧。

如果有4张图片 应该在最前面加上***一张 再在***面加上***张 这样当到最前面或者***面的时候 直接修改 TranslateX 达到循环的效果。

  1. <Style TargetType="snControls:SlideView"
  2.         <Setter Property="Background" Value="{x:Null}" /> 
  3.         <Setter Property="BorderThickness" Value="0" /> 
  4.         <Setter Property="TabNavigation" Value="Once" /> 
  5.         <Setter Property="IsTabStop" Value="False" /> 
  6.         <Setter Property="ItemsPanel"
  7.             <Setter.Value> 
  8.                 <ItemsPanelTemplate> 
  9.                     <VirtualizingStackPanel Orientation="Horizontal" /> 
  10.                 </ItemsPanelTemplate> 
  11.             </Setter.Value> 
  12.         </Setter> 
  13.         <Setter Property="Template"
  14.             <Setter.Value> 
  15.                 <ControlTemplate TargetType="snControls:SlideView"
  16.                     <Grid Background="{TemplateBinding Background}" 
  17.                           Height="{TemplateBinding Height}" 
  18.                           Width="{TemplateBinding Width}"
  19.                         <Border Height="{TemplateBinding Height}" 
  20.                                 BorderThickness="{TemplateBinding BorderThickness}" 
  21.                                 x:Name="InnerBorder"
  22.                             <ItemsPresenter x:Name="InnerItemsPresenter"
  23.                                 <ItemsPresenter.RenderTransform> 
  24.                                     <CompositeTransform/> 
  25.                                 </ItemsPresenter.RenderTransform> 
  26.                             </ItemsPresenter> 
  27.                         </Border> 
  28.                         <ListBox VerticalAlignment="Bottom" 
  29.                                  HorizontalAlignment="Center" 
  30.                                  x:Name="listMasker" 
  31.                                  ItemsSource="{TemplateBinding MarkSource}"
  32.                             <ListBox.ItemsPanel> 
  33.                                 <ItemsPanelTemplate> 
  34.                                     <VirtualizingStackPanel Orientation="Horizontal" /> 
  35.                                 </ItemsPanelTemplate> 
  36.                             </ListBox.ItemsPanel> 
  37.                             <ListBox.ItemTemplate> 
  38.                                 <DataTemplate> 
  39.                                     <Ellipse Margin="0 0 4 12" 
  40.                                              Width="8" 
  41.                                              Height="8" 
  42.                                              Tag="{Binding MarkIndex}"
  43.                                     </Ellipse> 
  44.                                 </DataTemplate> 
  45.                             </ListBox.ItemTemplate> 
  46.                         </ListBox> 
  47.                     </Grid> 
  48.                 </ControlTemplate> 
  49.             </Setter.Value> 
  50.         </Setter> 
  51.     </Style> 

颜色转换器

  1. public class SlideViewMarkColorConverter : IValueConverter 
  2.     { 
  3.         private SolidColorBrush brush = new SolidColorBrush(); 
  4.         public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
  5.         { 
  6.             if ((int)value == (int)parameter) 
  7.             { 
  8.                 brush.Opacity = 1
  9.                 brush.Color = Colors.White; 
  10.             } 
  11.             else  
  12.             { 
  13.                 brush.Opacity = 0.4
  14.                 brush.Color = Colors.Black; 
  15.             } 
  16.             return brush; 
  17.         } 
  18.  
  19.         public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
  20.         { 
  21.             throw new NotImplementedException(); 
  22.         } 
  23.     } 

MarkSource绑定实体,其中MarkIndex修改为实体的sn,如果实体数量大于1 ItemsSource前insert***一个 ItemsSource后add***个。

***如果将控件放在枢轴里面 是无法滑动的。

在页面后置代码loadevent里面加上

  1. slideview.UseOptimizedManipulationRouting = false
  2.             slideview.AddHandler(PivotItem.ManipulationStartedEvent, new EventHandler<ManipulationStartedEventArgs>(myPivotItem_ManipulationStarted), true); 
  3.             slideview.AddHandler(PivotItem.ManipulationDeltaEvent, new EventHandler<ManipulationDeltaEventArgs>(myPivotItem_ManipulationDelta), true); 
  4.             slideview.AddHandler(PivotItem.ManipulationCompletedEvent, new EventHandler<ManipulationCompletedEventArgs>(myPivotItem_ManipulationCompleted), true); 
myPivotItem_ManipulationStarted
myPivotItem_ManipulationDelta
myPivotItem_ManipulationCompleted 事件里面判断
  1. if (e.OriginalSource.GetType() == typeof(Image)) 
  2.             { 
  3.                 e.Handled = true
  4.             } 

本文链接:http://www.cnblogs.com/dingge38/archive/2014/08/01/3884716.html

责任编辑:chenqingxiang 来源: 戴眼镜的杀手博客
相关推荐

2013-12-18 11:17:00

微软WP

2014-07-16 09:15:44

Android LiOS 8WP8.1

2014-04-15 10:40:34

WP8.1Build2014

2013-03-27 10:12:29

Intel固态硬盘路线图

2014-08-06 09:26:14

Windows Pho

2021-08-04 07:02:25

Windows 11操作系统微软

2019-01-23 11:17:22

电脑程序员工作

2014-06-25 15:14:29

WP 8.1

2015-12-03 11:45:31

PHP7 发布

2015-11-09 17:01:45

AfterShokz

2014-04-14 11:23:27

WP8.1Build2014

2021-01-29 09:07:39

数据保护信息安全数据隐私

2023-08-03 08:42:24

2013-03-13 15:51:44

2013-10-18 09:25:56

Windows 8.1Windows

2018-11-23 10:58:17

黑五数据泄露数据保护

2023-11-30 12:07:21

人工智能CIO

2014-09-01 10:56:52

WP8

2015-10-21 16:11:39

WP支付宝

2014-10-15 16:47:31

Android微软
点赞
收藏

51CTO技术栈公众号