DevExpress中Carousel控件的应用

Carousel,直译为旋转木马,即旋转视图,可以做为数据的展示或者菜单项。

要实现触摸左右滑动的效果,其实是比较容易的,直接在CarouselPanel上实现MouseDown/MouseUp事件,在后台添加逻辑,判断是否产生了位置移动,从而控制面板向左或者向右移动子项。

下面介绍一下,Carousel具体使用方法:

1、添加一个CarouselItemsControl

2、设置CarouselItemsControl的ItemContainerStyle。

3、如果是通过数据绑定的,则可以设置ItemTemplate模板

4、ItemsPanel,一般是有默认的CarouselPanel。但是大部分情况下,都是要修改其中的样式及属性来达到界面的效果。CarouselPanel中值得关注的几点:

  A、ItemMovingPath,子项移动路径。通过设置好路径,子项移动的时候会按照固定路径。<PathGeometry Figures="M0,0 400,0" />

  B、ParameterSet,设置CarouselPanel中子项的相对属性,如Scale相对位置及大小、Opacity透明度、ZIndex堆叠-用来设置靠前靠后

样式设置好以后,可以通过直接绑定CarouselItemsControl的ItemSource,生成列表。

主要的也就这些,具体的细节,可以通过属性去设置。 

下面是Demo:

前台

  1. <Window x:Class="WpfApplication9.MainWindow"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:dxca="http://schemas.devexpress.com/winfx/2008/xaml/carousel"
  5. xmlns:collections="clr-namespace:System.Collections;assembly=mscorlib"
  6. xmlns:wpfApplication9="clr-namespace:WpfApplication9"
  7. Title="MainWindow" Height="300" Width="480">
  8. <Grid>
  9. <Grid>
  10. <Grid.Resources>
  11. <dxca:ParameterCollection x:Key="parameterSet">
  12. <dxca:Parameter Name="Scale">
  13. <dxca:Parameter.DistributionFunction>
  14. <dxca:PieceLinearFunction>
  15. <dxca:PieceLinearFunction.Points>
  16. <dxca:PointCollection>
  17. <Point X="0" Y="0" />
  18. <Point X="0.05" Y="0.1" />
  19. <Point X="0.5" Y="1" />
  20. <Point X="0.95" Y="0.1" />
  21. <Point X="1" Y="0" />
  22. </dxca:PointCollection>
  23. </dxca:PieceLinearFunction.Points>
  24. </dxca:PieceLinearFunction>
  25. </dxca:Parameter.DistributionFunction>
  26. </dxca:Parameter>
  27. <dxca:Parameter Name="Opacity" DistributionFunction="{StaticResource {ComponentResourceKey TypeInTargetAssembly={x:Type dxca:CarouselPanel}, ResourceId=Linear3PConvexNr}}" />
  28. <dxca:Parameter Name="ZIndex" DistributionFunction="{StaticResource {ComponentResourceKey TypeInTargetAssembly={x:Type dxca:CarouselPanel}, ResourceId=Linear3PConvexERIntMax}}" />
  29. </dxca:ParameterCollection>
  30. <!--<dxca:ParameterCollection x:Key="parameterSet">
  31. <dxca:Parameter Name="Scale" DistributionFunction="{StaticResource {ComponentResourceKey TypeInTargetAssembly={x:Type dxca:CarouselPanel}, ResourceId=Linear3PConvexNr}}" />
  32. <dxca:Parameter Name="Opacity" DistributionFunction="{StaticResource {ComponentResourceKey TypeInTargetAssembly={x:Type dxca:CarouselPanel}, ResourceId=Linear3PConvexNr}}" />
  33. <dxca:Parameter Name="ZIndex" DistributionFunction="{StaticResource {ComponentResourceKey TypeInTargetAssembly={x:Type dxca:CarouselPanel}, ResourceId=Linear3PConvexERIntMax}}" />
  34. </dxca:ParameterCollection>-->
  35. <collections:ArrayList x:Key="LanguageArray">
  36. <wpfApplication9:ContentModel Name="AAA1" Source="Chrysanthemum.jpg"/>
  37. <wpfApplication9:ContentModel Name="BBB2" Source="Desert.jpg"/>
  38. <wpfApplication9:ContentModel Name="CCC3" Source="Hydrangeas.jpg"/>
  39. <wpfApplication9:ContentModel Name="AAA4" Source="Jellyfish.jpg"/>
  40. <wpfApplication9:ContentModel Name="BBB5" Source="Koala.jpg"/>
  41. <wpfApplication9:ContentModel Name="CCC6" Source="Lighthouse.jpg"/>
  42. <wpfApplication9:ContentModel Name="BBB7" Source="Penguins.jpg"/>
  43. <wpfApplication9:ContentModel Name="CCC8" Source="Tulips.jpg"/>
  44. </collections:ArrayList>
  45. </Grid.Resources>
  46. <dxca:CarouselItemsControl x:Name="carouselItemsControl" ItemsSource="{StaticResource LanguageArray}" >
  47. <dxca:CarouselItemsControl.ItemContainerStyle>
  48. <Style TargetType="{x:Type ContentControl}">
  49. <Setter Property="RenderTransformOrigin" Value="0.5, 0.5" />
  50. <!--<Setter Property="Opacity" Value="{Binding Path=(dxca:CarouselPanel.Parameters).Opacity, RelativeSource={RelativeSource Self}}" />-->
  51. <Setter Property="Panel.ZIndex" Value="{Binding Path=(dxca:CarouselPanel.Parameters).ZIndex, RelativeSource={RelativeSource Self}}" />
  52. <Setter Property="RenderTransform">
  53. <Setter.Value>
  54. <TransformGroup>
  55. <ScaleTransform ScaleX="{Binding Path=(dxca:CarouselPanel.Parameters).Scale, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContentControl}}}"
  56. ScaleY="{Binding Path=(dxca:CarouselPanel.Parameters).Scale, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContentControl}}}"
  57. />
  58. <TranslateTransform X="{Binding Path=(dxca:CarouselPanel.Parameters).OffsetX, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContentControl}}}"
  59. Y="{Binding Path=(dxca:CarouselPanel.Parameters).OffsetY, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContentControl}}}"
  60. />
  61. </TransformGroup>
  62. </Setter.Value>
  63. </Setter>
  64. </Style>
  65. </dxca:CarouselItemsControl.ItemContainerStyle>
  66. <ItemsControl.ItemTemplate>
  67. <DataTemplate DataType="ItemsControl">
  68. <Grid>
  69. <Grid.RowDefinitions>
  70. <RowDefinition Height="*" />
  71. <RowDefinition Height="40"/>
  72. </Grid.RowDefinitions>
  73. <Image Source="{Binding Source}"></Image>
  74. <TextBlock Text="{Binding Path=Name}" Grid.Row="1" HorizontalAlignment="Center" FontSize="30" />
  75. </Grid>
  76. </DataTemplate>
  77. </ItemsControl.ItemTemplate>
  78. <ItemsControl.ItemsPanel>
  79. <ItemsPanelTemplate>
  80. <dxca:CarouselPanel RenderOptions.BitmapScalingMode="HighQuality" Margin="-200,0"
  81. x:Name="carousel" AnimationTime="400"
  82. VisibleItemCount="5" AttractorPointIndex="2"
  83. PathPadding="10, 0, 10, 0" PathVisible="False"
  84. ItemSize="200,200"
  85. IsAutoSizeItem="False"
  86. ClipToBounds="True"
  87. IsInvertedDirection="False"
  88. IsRepeat="False"
  89. ActivateItemOnClick="True"
  90. OffsetAnimationAddFunction="{StaticResource {ComponentResourceKey TypeInTargetAssembly={x:Type dxca:CarouselPanel}, ResourceId=InvertedSine}}"
  91. ParameterSet="{DynamicResource parameterSet}"
  92. MouseDown="Carousel_OnMouseDown" MouseUp="Carousel_OnMouseUp"
  93. >
  94. <dxca:CarouselPanel.ItemMovingPath>
  95. <PathGeometry Figures="M0,0 400,0" />
  96. </dxca:CarouselPanel.ItemMovingPath>
  97. </dxca:CarouselPanel>
  98. </ItemsPanelTemplate>
  99. </ItemsControl.ItemsPanel>
  100. </dxca:CarouselItemsControl >
  101. </Grid>
  102. </Grid>
  103. </Window>

后台

  1. public partial class MainWindow : Window
  2. {
  3. public MainWindow()
  4. {
  5. InitializeComponent();
  6. }
  7. private Point pt1, pt2 = new Point();
  8. private int firstTouchId = -;
  9.  
  10. private void Carousel_OnMouseDown(object sender, MouseButtonEventArgs e)
  11. {
  12. CarouselPanel _canvas = (CarouselPanel)sender as CarouselPanel;
  13. if (_canvas != null)
  14. {
  15. pt1 = e.GetPosition(_canvas);
  16. // Record the ID of the first touch point if it hasn't been recorded.
  17. }
  18. }
  19.  
  20. private void Carousel_OnMouseUp(object sender, MouseButtonEventArgs e)
  21. {
  22. CarouselPanel _canvas = (CarouselPanel)sender as CarouselPanel;
  23. if (_canvas != null)
  24. {
  25. pt2 = e.GetPosition(_canvas);
  26. // Record the ID of the first touch point if it hasn't been recorded.
  27. if (pt2.X < pt1.X)
  28. {
  29. _canvas.MoveNext();
  30. }
  31. else if (pt2.X > pt1.X)
  32. {
  33. _canvas.MovePrev();
  34. }
  35. }
  36. }
  37. }
  38. public class ContentModel
  39. {
  40. public string Name { get; set; }
  41. public ImageSource Source { get; set; }
  42. }

下面介绍一下菜单如何循环,如3个子项循环。

1、设置水平的几个子项在水平方向上的布局和大小比例

  1. <dxca:Parameter Name="Scale">
  2. <dxca:Parameter.DistributionFunction>
  3. <dxca:PieceLinearFunction>
  4. <dxca:PieceLinearFunction.Points>
  5. <dxca:PointCollection>
  6. <Point X="0.3" Y="0.5" />
  7. <Point X="0.5" Y="1" />
  8. <Point X="0.7" Y="0.5" />
  9. </dxca:PointCollection>
  10. </dxca:PieceLinearFunction.Points>
  11. </dxca:PieceLinearFunction>
  12. </dxca:Parameter.DistributionFunction>
  13. </dxca:Parameter>

2、CarouselPanel中设置 VisibleItemCount="3" AttractorPointIndex="1"  IsRepeat="True"

Margin和ItemSize则根据界面需要调整即可

DevExpress Carousel 设置水平滑动列表的更多相关文章

  1. Unity3d NGUI的使用(九)(UIScrollView制作滑动列表)

    UIScrollView制作滑动列表,可横向,竖直展示一些列表在固定可视范围内 UIScrollVIew只是一个可滑动的UI组件 如果需要制作复杂的可视区域UI需要配合使用UIPanel与UIGrid ...

  2. 使用泛型简单封装NGUI的ScrollView实现滑动列表

    懒,是老毛病了,周末跑了半马,跑完也是一通累,好久没锻炼了..也是懒的,有时都懒的写博客..最近看到项目中各种滑动列表框,本着要懒出水平来的原则,决定花点时间简单处理下(暂时未做列表太多时的优化):1 ...

  3. Android滑动列表(拖拽,左滑删除,右滑完成)功能实现(2)

    ItemTouchHelper类 之前我们实现了滑动列表的一些基本功能,为了实现更多的效果,我们来仔细看一下ItemTouchHelper中的类: ItemTouchHelper.SimpleCall ...

  4. [转]ionic3项目实战教程三(创建provider、http请求、图文列表、滑动列表)

    本文转自:https://blog.csdn.net/lyt_angularjs/article/details/81145468 版权声明:本文为博主原创文章,转载请注明出处.谢谢! https:/ ...

  5. bootstrap 列表--水平定义列表

    水平定义列表就像内联列表一样,Bootstrap可以给<dl>添加类名“.dl-horizontal”给定义列表实现水平显示效果. @media (min-width: 768px) { ...

  6. 自定义控件_水平滑动的View 自定义属性

    保持饥饿,保持愚蠢,我们对待事情本来应该就是这样的 接下来我要写一个水平滑动的自写义,实现效果 水平滑动我们有很多种实现方法,recyceryView,HorizontalScrollView都可以, ...

  7. 实现移动端touch事件的横向滑动列表效果

    要实现手机端横向滑动效果并不难,了解实现的原理及业务逻辑就很容易实现.原理:touchstart(手指按下瞬间获取相对于页面的位置)——>touchmove(手指移动多少,元素相应移动多少). ...

  8. ListVIew中包含水平滑动控件,左右滑动时容易触发上下滑动

    自定义ListView import android.content.Context;import android.util.AttributeSet;import android.view.Moti ...

  9. Android 手机卫士--设置界面&功能列表界面跳转逻辑处理

    在<Android 手机卫士--md5加密过程>中已经实现了加密类,这里接着实现手机防盗功能 本文地址:http://www.cnblogs.com/wuyudong/p/5941959. ...

随机推荐

  1. redis成长之路——(五)

    单例.哨兵.Cluster redis应用广泛,主要体现于实际场景的可用化,但是对于码农来说初步入手很多理念难以理解:码农的想法就是:为什么我要管那么多,我只想用,能用就行!所以必须将三个场景透明化. ...

  2. 解析大型.NET ERP系统 界面与逻辑分离

    Windows Forms程序实现界面与逻辑分离的关键是数据绑定技术(Data Binding),这与微软推出的ASP.NET MVC的原理相同,分离业务代码与界面层,提高系统的可维护性. 数据绑定 ...

  3. SQL Server 系列文章快速导航(SWF版)

    一.前言 在博客园写博客不自不觉已经有5个年头了,一开始只是为了记录工作中遇到的问题和解决办法,后来写的文章不自不觉的侧重在SQL Server方面的技术文章,在2014年1月终于鼓起勇气申请了微软S ...

  4. 匹夫细说C#:从园友留言到动手实现C#虚函数机制

    前言 上一篇文章匹夫通过CIL代码简析了一下C#函数调用的话题.虽然点击进来的童鞋并不如匹夫预料的那么多,但也还是有一些挺有质量的来自园友的回复.这不,就有一个园友提出了这样一个代码,这段代码如果被编 ...

  5. JS魔法堂:不完全国际化&本地化手册 之 实战篇

    前言  最近加入到新项目组负责前端技术预研和选型,其中涉及到一个熟悉又陌生的需求--国际化&本地化.熟悉的是之前的项目也玩过,陌生的是之前的实现仅仅停留在"有"的阶段而已. ...

  6. 我的runloop学习笔记

    前言:公司项目终于忙的差不多了,最近比较闲,想起叶大说过的iOS面试三把刀,GCD.runtime.runloop,runtime之前已经总结过了,GCD在另一篇博客里也做了一些小总结,今天准备把ru ...

  7. Redis简单案例(一) 网站搜索的热搜词

    对于一个网站来说,无论是商城网站还是门户网站,搜索框都是有一个比较重要的地位,它的存在可以说是 为了让用户更快.更方便的去找到自己想要的东西.对于经常逛这个网站的用户,当然也会想知道在这里比较“火” ...

  8. 执行插入语句,object val = cmd.ExecuteScalar() val = null

    在写接口的过程中遇到错误:空对象不能转换为值类型 因为我们使用的是petapoco,经过调试后发现是 object val = cmd.ExecuteScalar() 这一句造成的报错, val = ...

  9. IdentityServer4 ASP.NET Core的OpenID Connect OAuth 2.0框架学习保护API

    IdentityServer4 ASP.NET Core的OpenID Connect OAuth 2.0框架学习之保护API. 使用IdentityServer4 来实现使用客户端凭据保护ASP.N ...

  10. C++四种类型转换方式。

    类型转换有c风格的,当然还有c++风格的.c风格的转换的格式很简单(TYPE)EXPRESSION,但是c风格的类型转换有不少的缺点,有的时候用c风格的转换是不合适的,因为它可以在任意类型之间转换,比 ...