一直想写点东西,直到今天才真正动笔,唯一的原因就是太懒,太懒...
大家肯定熟悉安卓各种客户端首页联动图片广告(比如淘宝),可以自动滚动,可以手动滑动,当然是循环的。但是在wp上我看到的做的***的最早的当属爱壁纸了。
写在wp8.1的filpview马上来临之际。上代码吧。
如果有4张图片 应该在最前面加上***一张 再在***面加上***张 这样当到最前面或者***面的时候 直接修改 TranslateX 达到循环的效果。
- <Style TargetType="snControls:SlideView">
- <Setter Property="Background" Value="{x:Null}" />
- <Setter Property="BorderThickness" Value="0" />
- <Setter Property="TabNavigation" Value="Once" />
- <Setter Property="IsTabStop" Value="False" />
- <Setter Property="ItemsPanel">
- <Setter.Value>
- <ItemsPanelTemplate>
- <VirtualizingStackPanel Orientation="Horizontal" />
- </ItemsPanelTemplate>
- </Setter.Value>
- </Setter>
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate TargetType="snControls:SlideView">
- <Grid Background="{TemplateBinding Background}"
- Height="{TemplateBinding Height}"
- Width="{TemplateBinding Width}">
- <Border Height="{TemplateBinding Height}"
- BorderThickness="{TemplateBinding BorderThickness}"
- x:Name="InnerBorder">
- <ItemsPresenter x:Name="InnerItemsPresenter">
- <ItemsPresenter.RenderTransform>
- <CompositeTransform/>
- </ItemsPresenter.RenderTransform>
- </ItemsPresenter>
- </Border>
- <ListBox VerticalAlignment="Bottom"
- HorizontalAlignment="Center"
- x:Name="listMasker"
- ItemsSource="{TemplateBinding MarkSource}">
- <ListBox.ItemsPanel>
- <ItemsPanelTemplate>
- <VirtualizingStackPanel Orientation="Horizontal" />
- </ItemsPanelTemplate>
- </ListBox.ItemsPanel>
- <ListBox.ItemTemplate>
- <DataTemplate>
- <Ellipse Margin="0 0 4 12"
- Width="8"
- Height="8"
- Tag="{Binding MarkIndex}">
- </Ellipse>
- </DataTemplate>
- </ListBox.ItemTemplate>
- </ListBox>
- </Grid>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Style>
颜色转换器
- public class SlideViewMarkColorConverter : IValueConverter
- {
- private SolidColorBrush brush = new SolidColorBrush();
- public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
- {
- if ((int)value == (int)parameter)
- {
- brush.Opacity = 1;
- brush.Color = Colors.White;
- }
- else
- {
- brush.Opacity = 0.4;
- brush.Color = Colors.Black;
- }
- return brush;
- }
- public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
MarkSource绑定实体,其中MarkIndex修改为实体的sn,如果实体数量大于1 ItemsSource前insert***一个 ItemsSource后add***个。
***如果将控件放在枢轴里面 是无法滑动的。
在页面后置代码loadevent里面加上
- slideview.UseOptimizedManipulationRouting = false;
- slideview.AddHandler(PivotItem.ManipulationStartedEvent, new EventHandler<ManipulationStartedEventArgs>(myPivotItem_ManipulationStarted), true);
- slideview.AddHandler(PivotItem.ManipulationDeltaEvent, new EventHandler<ManipulationDeltaEventArgs>(myPivotItem_ManipulationDelta), true);
- slideview.AddHandler(PivotItem.ManipulationCompletedEvent, new EventHandler<ManipulationCompletedEventArgs>(myPivotItem_ManipulationCompleted), true);
myPivotItem_ManipulationStarted
myPivotItem_ManipulationDelta
myPivotItem_ManipulationCompleted 事件里面判断
- if (e.OriginalSource.GetType() == typeof(Image))
- {
- e.Handled = true;
- }
本文链接:http://www.cnblogs.com/dingge38/archive/2014/08/01/3884716.html