这篇文章运用简单易懂的例子给大家介绍使用WPF制作一个手风琴式轮播图效果,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
专注于为中小企业提供成都网站建设、成都网站设计服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业昂昂溪免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了上1000+企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。实现效果如下:
步骤:
1、自定义控件MyImageControl
实现图片的裁切和动画的赋值。
public partial class MyImageControl : UserControl { public static readonly DependencyProperty ShowImageProperty = DependencyProperty.Register("ShowImage", typeof(BitmapImage), typeof(MyImageControl), new PropertyMetadata(null)); public BitmapImage ShowImage { get { return (BitmapImage)GetValue(ShowImageProperty); } set { SetValue(ShowImageProperty, value); } } public MyImageControl() { InitializeComponent(); } public Storyboard storyboard = new Storyboard(); private const int FlipCount = 5; BitmapSource[] bitmap = new BitmapSource[FlipCount]; Image[] images = new Image[FlipCount]; public void GetHorizontalFlip() { int partImgWidth = (int)this.ShowImage.PixelWidth; int partImgHeight = (int)(this.ShowImage.PixelHeight / FlipCount); for (int i = 0; i < FlipCount; i++) { bitmap[i] = GetPartImage(this.ShowImage, 0, i * partImgHeight, partImgWidth, partImgHeight); images[i] = new Image() { Width = partImgWidth, Height = partImgHeight, Source = bitmap[i], }; Canvas.SetTop(images[i], i * partImgHeight); this.mainCanvas.Children.Add(images[i]); DoubleAnimation da = new DoubleAnimation(0, (int)this.ShowImage.PixelWidth, new Duration(TimeSpan.FromMilliseconds((i + 1) * 250)), FillBehavior.HoldEnd); storyboard.Children.Add(da); Storyboard.SetTarget(da, images[i]); Storyboard.SetTargetProperty(da, new PropertyPath("(Canvas.Left)")); } storyboard.FillBehavior = FillBehavior.HoldEnd; storyboard.Completed += new EventHandler(Storyboard_Completed); } private void Storyboard_Completed(object sender, EventArgs e) { this.mainCanvas.Children.Clear(); storyboard.Children.Clear(); } private BitmapSource GetPartImage(BitmapImage img, int XCoordinate, int YCoordinate, int Width, int Height) { return new CroppedBitmap(img, new Int32Rect(XCoordinate, YCoordinate, Width, Height)); } }
本文标题:使用WPF制作一个手风琴式轮播图效果-创新互联
网址分享:https://www.cdcxhl.com/article48/shgep.html
成都网站建设公司_创新互联,为您提供App设计、微信小程序、域名注册、面包屑导航、虚拟主机、动态网站
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联