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:

前台

<Window x:Class="WpfApplication9.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxca="http://schemas.devexpress.com/winfx/2008/xaml/carousel"
xmlns:collections="clr-namespace:System.Collections;assembly=mscorlib"
xmlns:wpfApplication9="clr-namespace:WpfApplication9"
Title="MainWindow" Height="300" Width="480">
<Grid>
<Grid>
<Grid.Resources>
<dxca:ParameterCollection x:Key="parameterSet">
<dxca:Parameter Name="Scale">
<dxca:Parameter.DistributionFunction>
<dxca:PieceLinearFunction>
<dxca:PieceLinearFunction.Points>
<dxca:PointCollection>
<Point X="0" Y="0" />
<Point X="0.05" Y="0.1" />
<Point X="0.5" Y="1" />
<Point X="0.95" Y="0.1" />
<Point X="1" Y="0" />
</dxca:PointCollection>
</dxca:PieceLinearFunction.Points>
</dxca:PieceLinearFunction>
</dxca:Parameter.DistributionFunction>
</dxca:Parameter>
<dxca:Parameter Name="Opacity" DistributionFunction="{StaticResource {ComponentResourceKey TypeInTargetAssembly={x:Type dxca:CarouselPanel}, ResourceId=Linear3PConvexNr}}" />
<dxca:Parameter Name="ZIndex" DistributionFunction="{StaticResource {ComponentResourceKey TypeInTargetAssembly={x:Type dxca:CarouselPanel}, ResourceId=Linear3PConvexERIntMax}}" />
</dxca:ParameterCollection>
<!--<dxca:ParameterCollection x:Key="parameterSet">
<dxca:Parameter Name="Scale" DistributionFunction="{StaticResource {ComponentResourceKey TypeInTargetAssembly={x:Type dxca:CarouselPanel}, ResourceId=Linear3PConvexNr}}" />
<dxca:Parameter Name="Opacity" DistributionFunction="{StaticResource {ComponentResourceKey TypeInTargetAssembly={x:Type dxca:CarouselPanel}, ResourceId=Linear3PConvexNr}}" />
<dxca:Parameter Name="ZIndex" DistributionFunction="{StaticResource {ComponentResourceKey TypeInTargetAssembly={x:Type dxca:CarouselPanel}, ResourceId=Linear3PConvexERIntMax}}" />
</dxca:ParameterCollection>-->
<collections:ArrayList x:Key="LanguageArray">
<wpfApplication9:ContentModel Name="AAA1" Source="Chrysanthemum.jpg"/>
<wpfApplication9:ContentModel Name="BBB2" Source="Desert.jpg"/>
<wpfApplication9:ContentModel Name="CCC3" Source="Hydrangeas.jpg"/>
<wpfApplication9:ContentModel Name="AAA4" Source="Jellyfish.jpg"/>
<wpfApplication9:ContentModel Name="BBB5" Source="Koala.jpg"/>
<wpfApplication9:ContentModel Name="CCC6" Source="Lighthouse.jpg"/>
<wpfApplication9:ContentModel Name="BBB7" Source="Penguins.jpg"/>
<wpfApplication9:ContentModel Name="CCC8" Source="Tulips.jpg"/>
</collections:ArrayList>
</Grid.Resources>
<dxca:CarouselItemsControl x:Name="carouselItemsControl" ItemsSource="{StaticResource LanguageArray}" >
<dxca:CarouselItemsControl.ItemContainerStyle>
<Style TargetType="{x:Type ContentControl}">
<Setter Property="RenderTransformOrigin" Value="0.5, 0.5" />
<!--<Setter Property="Opacity" Value="{Binding Path=(dxca:CarouselPanel.Parameters).Opacity, RelativeSource={RelativeSource Self}}" />-->
<Setter Property="Panel.ZIndex" Value="{Binding Path=(dxca:CarouselPanel.Parameters).ZIndex, RelativeSource={RelativeSource Self}}" />
<Setter Property="RenderTransform">
<Setter.Value>
<TransformGroup>
<ScaleTransform ScaleX="{Binding Path=(dxca:CarouselPanel.Parameters).Scale, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContentControl}}}"
ScaleY="{Binding Path=(dxca:CarouselPanel.Parameters).Scale, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContentControl}}}"
/>
<TranslateTransform X="{Binding Path=(dxca:CarouselPanel.Parameters).OffsetX, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContentControl}}}"
Y="{Binding Path=(dxca:CarouselPanel.Parameters).OffsetY, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContentControl}}}"
/>
</TransformGroup>
</Setter.Value>
</Setter>
</Style>
</dxca:CarouselItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="ItemsControl">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<Image Source="{Binding Source}"></Image>
<TextBlock Text="{Binding Path=Name}" Grid.Row="1" HorizontalAlignment="Center" FontSize="30" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<dxca:CarouselPanel RenderOptions.BitmapScalingMode="HighQuality" Margin="-200,0"
x:Name="carousel" AnimationTime="400"
VisibleItemCount="5" AttractorPointIndex="2"
PathPadding="10, 0, 10, 0" PathVisible="False"
ItemSize="200,200"
IsAutoSizeItem="False"
ClipToBounds="True"
IsInvertedDirection="False"
IsRepeat="False"
ActivateItemOnClick="True"
OffsetAnimationAddFunction="{StaticResource {ComponentResourceKey TypeInTargetAssembly={x:Type dxca:CarouselPanel}, ResourceId=InvertedSine}}"
ParameterSet="{DynamicResource parameterSet}"
MouseDown="Carousel_OnMouseDown" MouseUp="Carousel_OnMouseUp"
>
<dxca:CarouselPanel.ItemMovingPath>
<PathGeometry Figures="M0,0 400,0" />
</dxca:CarouselPanel.ItemMovingPath>
</dxca:CarouselPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</dxca:CarouselItemsControl >
</Grid>
</Grid>
</Window>

后台

 public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private Point pt1, pt2 = new Point();
private int firstTouchId = -; private void Carousel_OnMouseDown(object sender, MouseButtonEventArgs e)
{
CarouselPanel _canvas = (CarouselPanel)sender as CarouselPanel;
if (_canvas != null)
{
pt1 = e.GetPosition(_canvas);
// Record the ID of the first touch point if it hasn't been recorded.
}
} private void Carousel_OnMouseUp(object sender, MouseButtonEventArgs e)
{
CarouselPanel _canvas = (CarouselPanel)sender as CarouselPanel;
if (_canvas != null)
{
pt2 = e.GetPosition(_canvas);
// Record the ID of the first touch point if it hasn't been recorded.
if (pt2.X < pt1.X)
{
_canvas.MoveNext();
}
else if (pt2.X > pt1.X)
{
_canvas.MovePrev();
}
}
}
}
public class ContentModel
{
public string Name { get; set; }
public ImageSource Source { get; set; }
}

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

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

    <dxca:Parameter Name="Scale">
<dxca:Parameter.DistributionFunction>
<dxca:PieceLinearFunction>
<dxca:PieceLinearFunction.Points>
<dxca:PointCollection>
<Point X="0.3" Y="0.5" />
<Point X="0.5" Y="1" />
<Point X="0.7" Y="0.5" />
</dxca:PointCollection>
</dxca:PieceLinearFunction.Points>
</dxca:PieceLinearFunction>
</dxca:Parameter.DistributionFunction>
</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. C#设计模式-责任链模式

    在现实生活中,有很多请求并不是一个人说了就算的,例如面试时的工资,低于1万的薪水可能技术经理就可以决定了,但是1万~1万5的薪水可能技术经理就没这个权利批准,可能就需要请求技术总监的批准,所以在面试的 ...

  2. 【CSS3动画】transform对文字及图片的旋转、缩放、倾斜和移动

    前言:之前我有写过CSS3的transform这一这特性,对于它的用法,还不是很透彻,今天补充补充,呵呵 你懂的,小司机准备开车了. a)再提一提transform的四个属性 ①旋转--->ro ...

  3. 00.Web大前端时代之:HTML5+CSS3入门系列~Bug反馈文章

    感谢广大网友的热心提醒,现已发现如下错误: 感谢 “ ”对画布笔记系列的反馈(QQ:350223285) 这个是失误,strokeStyle和stroke对应 待续.... 欢迎提出更多问题,感谢大家 ...

  4. 【CSS进阶】试试酷炫的 3D 视角

    写这篇文章的缘由是因为看到了这个页面: 戳我看看(移动端页面,使用模拟器观看) 运用 CSS3 完成的 3D 视角,虽然有一些晕3D,但是使人置身于其中的交互体验感觉非常棒,运用在移动端制作一些 H5 ...

  5. Log4net入门(WCF篇)

    在上一篇Log4net入门(ASP.NET MVC 5篇)中,我们讲述了如何在ASP.NET MVC 5项目中使用log4net.在这一篇中,我们将讲述如何在WCF应用中使用log4net,为了讲述这 ...

  6. 计算机程序的思维逻辑 (38) - 剖析ArrayList

    从本节开始,我们探讨Java中的容器类,所谓容器,顾名思义就是容纳其他数据的,计算机课程中有一门课叫数据结构,可以粗略对应于Java中的容器类,我们不会介绍所有数据结构的内容,但会介绍Java中的主要 ...

  7. 支持高并发的IIS Web服务器常用设置

    适用的IIS版本:IIS 7.0, IIS 7.5, IIS 8.0 适用的Windows版本:Windows Server 2008, Windows Server 2008 R2, Windows ...

  8. 打造android偷懒神器———RecyclerView的万能适配器

    转载请注明出处谢谢:http://www.cnblogs.com/liushilin/p/5720926.html 很不好意思让大家久等了,本来昨天就应该写这个的,无奈公司昨天任务比较紧,所以没能按时 ...

  9. 你真的会玩SQL吗?查询指定节点及其所有父节点的方法

    --查询ID = '009'的所有父节点 ' ;WITH T AS ( SELECT ID , PID , NAME FROM TB WHERE ID = @ID UNION ALL SELECT A ...

  10. 《HelloGitHub月刊》第06期

    前言 <HelloGitHub>月刊做到第06期了(已经做了6个月了),在GitHub上获得了100+的stars,虽然不多,但是我很知足了,说明有人觉得这个项目是有价值的.同时园子中的' ...