• 大小: 10KB
    文件类型: .cs
    金币: 1
    下载: 0 次
    发布日期: 2021-06-08
  • 语言: C#
  • 标签: C#  WPF  轮播图  

资源简介

这个类是C# WPF功能的轮播图,只有一个类,简单。 用的时候 直接实例化,然后将需要轮播的List传进去,是参考网上的一个Demo,但是那个Demo耗内存,我修改了一下

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Threading;

namespace KthSelfDataServiceClient
{
    public class ActiveImageAutoScroll : UserControl
    {
        private static List ScrollImages;
        private Image imgAdvertPic = new Image()
        {
            Stretch = Stretch.Uniform
        };
        public Grid MainGrid = new Grid()
        {
            HorizontalAlignment = HorizontalAlignment.Stretch
            VerticalAlignment = VerticalAlignment.Stretch
        };
        public WrapPanel btnPanel = new WrapPanel();
        DoubleAnimation doubleAnimation = new DoubleAnimation(); //创建双精度动画对象

        public static DependencyProperty advertPicList = DependencyProperty.Register(“advertPicList“
            typeof(List) typeof(ActiveImageAutoScroll)
            new Propertymetadata(new PropertyChangedCallback(ScrollImagesCreateActive)));

        public static DependencyProperty advertPicStayTime = DependencyProperty.Register(“advertPicStayTime“
            typeof(List) typeof(ActiveImageAutoScroll)
            new Propertymetadata(new PropertyChangedCallback(loadAdvertStayTime)));

        public static DependencyProperty isShowPageNumBtn = DependencyProperty.Register(“isShowPageNumBtn“
            typeof(bool) typeof(ActiveImageAutoScroll)
            new Propertymetadata(new PropertyChangedCallback(showPageNum)));

        public List AdvertPicStayTime
        {
            get { return (List)GetValue(advertPicStayTime); }
            set { SetValue(advertPicStayTime value); }
        }

        public List AdvertPicList
        {
            get { return (List)GetValue(advertPicList); }
            set { SetValue(advertPicList value); }
        }

        public bool IsShowPageNumBtn
        {
            get { return (bool)GetValue(isShowPageNumBtn); }
            set {
                SetValue(isShowPageNumBtn value);
                if (!IsShowPageNumBtn)
                {
                    btnPanel.Visibility = Visibility.Collapsed;
                }
                else
                {
                    btnPanel.Visibility = Visibility.Visible;
                }
            }
        }
        private static void ScrollImagesCreateActive(Dependencyobject sender DependencyPropertyChangedEventArgs e)
        {
            ActiveImageAutoScroll advertPicControl = (ActiveImageAutoScroll)sender;
            if (e.Property == advertPicList)
            {
                advertPicControl.AdvertPicList = (List)e.NewValue;
                ScrollImages = advertPicControl.AdvertPicList;
            }
        }
        private static void loadAdvertStayTim

评论

共有 条评论