WPF图片轮播控件实例

图片轮播控件,自动播放,下一张,上一张,双击缩放,鼠标悬停,功能模块独立,可按需求删减。以下是用例步骤。

第一步:创建UserControl,

第二步:修改命名空间

第三步:修改数据源

CS代码:

using CS.View.Common.SY;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace CS
{
    /// <summary>
    /// ImgListBoxs.xaml 的交互逻辑
    /// </summary>
    public partial class ImgListBox : UserControl
    {
        public ImgListBox()
        {
            InitializeComponent();
            GitImagesList();
            RollBox();
        }



        /// <summary>
        /// 计时器
        /// </summary>
        DispatcherTimer dispatcherTimer = new DispatcherTimer();
        public void RollBox()
        {
            dispatcherTimer.Interval = TimeSpan.FromSeconds(5);
            dispatcherTimer.Tick += (object sender, EventArgs e) =>
            {
                Index++;
            };
            dispatcherTimer.Start();
        }



        /// <summary>
        /// 给控件添加图片
        /// </summary>
        public void GitImagesList()
        {
            //首次添加图片
            BitmapImage t = new BitmapImage(new Uri(vs[preindex], UriKind.Relative));
            one_img.Source = t;
            BitmapImage s = new BitmapImage(new Uri(vs[Index], UriKind.Relative));
            two_img.Source = s;
            //创建轮播底部按钮
            for (int i = 0; i < vs.Length; i++)
            {
                PART_ListBox.Items.Add(new ListBoxItem());
            }
            Binding binding = new Binding();
            binding.Path = new PropertyPath("Index");
            binding.Source = this;
            binding.Mode = BindingMode.TwoWay;
            PART_ListBox.SetBinding(ListBox.SelectedIndexProperty, binding);
        }



        //数据源
        string[] vs = { "/Assets/Picture/Pic1.jpg", "/Assets/Picture/Pic1.jpg", "/Assets/Picture/Pmg3.jpg", "/Assets/Picture/Pmg2.jpg", "/Assets/Picture/Pmg3.jpg" };
        Binding imgbing = new Binding("MaxIma");
        public List<FrameworkElement> Items { get; set; } = new List<FrameworkElement>();
        public event PropertyChangedEventHandler PropertyChanged;
        int preindex = 0;
        public int _Index { get; se
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值