最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

WPF實現(xiàn)手風(fēng)琴式輪播圖切換效果

 更新時間:2020年09月01日 13:44:07   作者:RunnerDNA  
這篇文章主要為大家詳細(xì)介紹了WPF實現(xiàn)手風(fēng)琴式輪播圖切換效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了WPF實現(xiàn)輪播圖切換效果的具體代碼,供大家參考,具體內(nèi)容如下

實現(xiàn)效果如下:

步驟:

1、自定義控件MyImageControl

實現(xiàn)圖片的裁切和動畫的賦值。

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));
    }
  }

2、自定義輪播控件

實現(xiàn)圖片點擊輪播和動畫的啟動。

public partial class MyRollControl : UserControl
  {
    public MyRollControl()
    {
      InitializeComponent();
    }
 
    /// <summary>
    /// 是否開始滾動
    /// </summary>
    public bool isBegin = false;
 
    /// <summary>
    /// 本輪剩余滾動數(shù)
    /// </summary>
    public int rollNum = 0;
 
    private List<BitmapImage> _ls_images;
    /// <summary>
    /// 滾動圖片組
    /// </summary>
    public List<BitmapImage> ls_images
    {
      set
      {
        if (rollNum > 0)
        {
          // 本輪滾動未結(jié)束
        }
        else
        {
          // 開始新的一輪滾動
          _ls_images = value;
          rollNum = _ls_images.Count();
        }
      }
      get { return _ls_images; }
    }
 
    private int n_index = 0;// 滾動索引
 
    /// <summary>
    /// 啟動
    /// </summary>
    public void Begin()
    {
      if (!isBegin)
      {
        isBegin = true;
 
        this.ResetStory();
        this.controlFront.GetHorizontalFlip();
      }
    }
 
    /// <summary>
    /// 初始化圖片
    /// </summary>
    void ResetStory()
    {
      if (this.ls_images.Count > 0)
      {
        this.controlFront.ShowImage = this.ls_images[this.n_index++ % this.ls_images.Count];
        this.controlBack.ShowImage = this.ls_images[this.n_index % this.ls_images.Count];
      }
    }
 
    private void mainGrid_MouseDown(object sender, MouseButtonEventArgs e)
    {
      if (this.controlFront.storyboard.Children.Count > 0)
      {
        if(this.controlBack.storyboard.Children.Count <= 0)
        {
          Canvas.SetZIndex(this.controlFront, 0);
          this.controlFront.storyboard.Begin();
          this.controlBack.GetHorizontalFlip();
          rollNum--;
          this.ResetStory();
        }
      }
      else if(this.controlFront.storyboard.Children.Count <= 0)
      {
        if(this.controlBack.storyboard.Children.Count > 0)
        {
          this.controlBack.storyboard.Begin();
          
          rollNum--;
          this.ResetStory();
          Canvas.SetZIndex(this.controlFront, -1);
          this.controlFront.GetHorizontalFlip();
        }
      }
    }
  }

3、主窗體調(diào)用后臺邏輯

public partial class MainWindow : Window
  {
    public MainWindow()
    {
      InitializeComponent();
 
      List<BitmapImage> ls_adv_img = new List<BitmapImage>();
      List<string> listAdv = GetUserImages(@"C:\Image");
      foreach (string a in listAdv)
      {
        BitmapImage img = new BitmapImage(new Uri(a));
        ls_adv_img.Add(img);
      }
      this.rollImg.ls_images = ls_adv_img;
      this.rollImg.Begin();
    }
 
    /// <summary>
    /// 獲取當(dāng)前用戶的圖片文件夾中的圖片路徑列表(不包含子文件夾)
    /// </summary>
    private List<string> GetUserImages(string path)
    {
      List<string> images = new List<string>();
      DirectoryInfo dir = new DirectoryInfo(path);
      FileInfo[] files = GetPicFiles(path, "*.jpg,*.png,*.bmp,", SearchOption.TopDirectoryOnly);
 
      if (files != null)
      {
        foreach (FileInfo file in files)
        {
          images.Add(file.FullName);
        }
      }
      return images;
    }
 
    private FileInfo[] GetPicFiles(string picPath, string searchPattern, SearchOption searchOption)
    {
      List<FileInfo> ltList = new List<FileInfo>();
      DirectoryInfo dir = new DirectoryInfo(picPath);
      string[] sPattern = searchPattern.Replace(';', ',').Split(',');
      for (int i = 0; i < sPattern.Length; i++)
      {
        FileInfo[] files = null;
        try
        {
          files = dir.GetFiles(sPattern[i], searchOption);
        }
        catch (System.Exception ex)
        {
          files = new FileInfo[] { };
        }
 
        ltList.AddRange(files);
      }
      return ltList.ToArray();
    }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。 

相關(guān)文章

  • C#中的Image控件用法詳解與實際應(yīng)用示例

    C#中的Image控件用法詳解與實際應(yīng)用示例

    在C#應(yīng)用程序開發(fā)中,圖像顯示是一個常見的需求,無論是創(chuàng)建圖形界面還是處理圖像數(shù)據(jù),System.Windows.Controls.Image控件都是實現(xiàn)這一目標(biāo)的重要工具,本文將詳細(xì)介紹Image控件的功能、用法、優(yōu)化技巧以及一些實際應(yīng)用示例,需要的朋友可以參考下
    2024-06-06
  • C# 串口接收數(shù)據(jù)中serialPort.close()死鎖的實例

    C# 串口接收數(shù)據(jù)中serialPort.close()死鎖的實例

    下面小編就為大家分享一篇C# 串口接收數(shù)據(jù)中serialPort.close()死鎖的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2017-11-11
  • Unity使用ScrollRect制作翻頁

    Unity使用ScrollRect制作翻頁

    這篇文章主要為大家詳細(xì)介紹了Unity使用ScrollRect制作翻頁,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-04-04
  • C#實現(xiàn)IDisposable接口釋放非托管資源

    C#實現(xiàn)IDisposable接口釋放非托管資源

    這篇文章主要為大家介紹了C#實現(xiàn)IDisposable接口釋放非托管資源,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-05-05
  • C#實現(xiàn)獲取電腦中的端口號和硬件信息

    C#實現(xiàn)獲取電腦中的端口號和硬件信息

    這篇文章主要為大家詳細(xì)介紹了C#實現(xiàn)獲取電腦中的端口號和硬件信息的相關(guān)方法,文中的示例代碼講解詳細(xì),有需要的小伙伴可以參考一下
    2025-01-01
  • C# 中使用Stopwatch計時器實現(xiàn)暫停計時繼續(xù)計時功能

    C# 中使用Stopwatch計時器實現(xiàn)暫停計時繼續(xù)計時功能

    這篇文章主要介紹了C# 中使用Stopwatch計時器可暫停計時繼續(xù)計時,主要介紹stopwatch的實例代碼詳解,代碼簡單易懂,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-03-03
  • C#實現(xiàn)在服務(wù)器端裁剪圖片的方法

    C#實現(xiàn)在服務(wù)器端裁剪圖片的方法

    這篇文章主要介紹了C#實現(xiàn)在服務(wù)器端裁剪圖片的方法,涉及C#操作圖片的相關(guān)技巧,需要的朋友可以參考下
    2015-04-04
  • C#編寫SqlHelper類

    C#編寫SqlHelper類

    在C#中使用ADO.NET連接數(shù)據(jù)庫的時候,每次連接都要編寫連接,打開,執(zhí)行SQL語句的代碼,很麻煩,編寫一個SqlHelper類,把每次連接都要寫的代碼封裝成方法,把要執(zhí)行的SQL語句通過參數(shù)傳進(jìn)去,可以大大簡化編碼
    2017-09-09
  • WPF利用TabControl控件實現(xiàn)拖拽排序功能

    WPF利用TabControl控件實現(xiàn)拖拽排序功能

    在UI交互中,拖拽操作是一種非常簡單友好的交互,這篇文章主要為大家介紹了WPF如何利用TabControl控件實現(xiàn)拖拽排序功能,需要的小伙伴可以參考一下
    2023-10-10
  • C# Windows API應(yīng)用之基于GetDesktopWindow獲得桌面所有窗口句柄的方法

    C# Windows API應(yīng)用之基于GetDesktopWindow獲得桌面所有窗口句柄的方法

    這篇文章主要介紹了C# Windows API應(yīng)用之基于GetDesktopWindow獲得桌面所有窗口句柄的方法,結(jié)合實例形式分析了GetDesktopWindow函數(shù)用于獲取窗口句柄的具體使用方法與相關(guān)注意事項,需要的朋友可以參考下
    2016-08-08

最新評論

昌邑市| 依兰县| 武乡县| 泰宁县| 鄂托克前旗| 阳东县| 连云港市| 古交市| 威远县| 金湖县| 拉孜县| 樟树市| 叶城县| 普格县| 玉山县| 吴堡县| 黄山市| 阳山县| 牡丹江市| 德清县| 黑水县| 五大连池市| 德江县| 新宾| 镇江市| 梁山县| 阿合奇县| 光泽县| 光山县| 准格尔旗| 太康县| 衡东县| 绵竹市| 盐亭县| 三台县| 威远县| 攀枝花市| 礼泉县| 福贡县| 色达县| 远安县|