欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來(lái)到入門(mén)教程網(wǎng)!

C#教程

當(dāng)前位置:主頁(yè) > 軟件編程 > C#教程 >

Silverlight實(shí)現(xiàn)跑馬燈動(dòng)畫(huà)

來(lái)源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C#教程|點(diǎn)擊: 次

本文實(shí)例為大家分享了Silverlight實(shí)現(xiàn)跑馬燈效果的具體代碼,供大家參考,具體內(nèi)容如下

主要功能有以下幾點(diǎn):

1、使用動(dòng)畫(huà)屬性驅(qū)動(dòng)圖片運(yùn)動(dòng)動(dòng)畫(huà)

2、圖片循環(huán)到最后一張后會(huì)自動(dòng)循環(huán)

3、當(dāng)鼠標(biāo)放到圖片時(shí)運(yùn)動(dòng)的圖片會(huì)停止,當(dāng)鼠標(biāo)離開(kāi)時(shí)暫停的圖片會(huì)繼續(xù)運(yùn)動(dòng)

4、當(dāng)鼠標(biāo)點(diǎn)擊任何一個(gè)圖片時(shí),該圖片會(huì)顯示真正大小

XAML:

<Grid x:Name="Layout" Background="White">
  <Canvas x:Name="canvas" Background="Black" Grid.Row="1" Height="280">
    <!--隱藏矩形以外的其它部分-->
    <Canvas.Clip >
     <RectangleGeometry x:Name="rg" />
    </Canvas.Clip>
  <StackPanel x:Name="sp" Orientation="Horizontal" ></StackPanel>
  </Canvas>
 <Image x:Name="img_Full" Width="640" Height="480" Visibility="Collapsed" MouseLeftButtonUp="img_Full_MouseLeftButtonUp" />
</Grid>

界面由Grid、Canvas、StackPanel和一個(gè)Image組成,Image用來(lái)顯示圖片的真實(shí)尺寸。

 public partial class Demo : UserControl
  {
    //定義
    private Storyboard storyboard;
    private const double photowidth = 320;
    private double totalwidth;
    public Demo()
    {
      InitializeComponent();
      CreatePhoto();
    }
    /// <summary>
    /// 創(chuàng)建圖片列表
    /// </summary>
    private void CreatePhoto()
    {
      string[] picList = new string[] { "1.jpg", "2.jpg", "3.jpg", "4.jpg", "5.jpg" };
      //創(chuàng)建多組圖片,保證圖片不會(huì)出現(xiàn)空白,因?yàn)镾tackPanel是橫向排列的,這樣就可以把圖片類(lèi)似模擬的排成一圈
      for (int i = 0; i < 3; i++)
      {
        //根據(jù)數(shù)組創(chuàng)建圖片
        for (int j = 0; j < picList.Length; j++)
        {
          UC_pic pic = new UC_pic();
          pic.ImageUrl = "../images/photo/" + picList[j];
          pic.Width = photowidth;
          //綁定事件
          pic.MouseEnter += new MouseEventHandler(pic_MouseEnter);
          pic.MouseLeave += new MouseEventHandler(pic_MouseLeave);
          pic.MouseLeftButtonUp += new MouseButtonEventHandler(pic_MouseLeftButtonUp);
          //添加對(duì)象到StackPanel中
          sp.Children.Add(pic);
        }
      }
      //計(jì)算圖片的總寬度
      totalwidth = -1.0 * photowidth * picList.Length;
      Canvas.SetLeft(sp, totalwidth);
      //調(diào)用初始化 方法
      CreateStoryboard();
      //播放動(dòng)畫(huà)
      storyboard.Begin();
      //重新繪制區(qū)域
      Resize();
 
    }
    /// <summary>
    /// 創(chuàng)建故事面板
    /// </summary>
    private void CreateStoryboard()
    {
      //創(chuàng)建故事面板
      storyboard = new Storyboard();
      DoubleAnimation animation = new DoubleAnimation();
      //設(shè)置動(dòng)畫(huà)延時(shí)
      animation.Duration = new Duration(TimeSpan.FromSeconds(2.0));
      //設(shè)置對(duì)象的作用屬性
      Storyboard.SetTarget(animation, sp);
      Storyboard.SetTargetProperty(animation, new PropertyPath("(Canvas.Left)", new object[0]));
      //添加到動(dòng)畫(huà)故事板內(nèi)
      storyboard.Children.Add(animation);
      //動(dòng)畫(huà)自動(dòng)完成事件
      storyboard.Completed += new EventHandler(storyboard_Completed);
    }
 
    //動(dòng)畫(huà)自動(dòng)完成事件,當(dāng)動(dòng)畫(huà)播放完成(結(jié)束)的時(shí)候。再次循環(huán)動(dòng)畫(huà)
    void storyboard_Completed(object sender, EventArgs e)
    {
      DoubleAnimation animation = (DoubleAnimation)storyboard.Children[0];
      //取得圖片當(dāng)前位置
      double left = Canvas.GetLeft(sp);
      //如果圖片已接近最后,就重新設(shè)置位置
      if (left > (totalwidth - photowidth))
      {
        animation.From = new double?(left);
      }
      //設(shè)置動(dòng)畫(huà)的起始值(From)所依據(jù)的總量(總長(zhǎng)度)
      animation.By = new double?(totalwidth);
      //循環(huán)動(dòng)畫(huà)
      storyboard.Begin();
    }
    private void Resize()
    {
      //重新繪制顯示區(qū)域
      rg.Rect = new Rect(0, 0, this.ActualWidth, 260);
    }
 
    void pic_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
      //顯示放大圖片
      UC_pic pic = sender as UC_pic;
      img_Full.Source = pic.photo.Source;
      img_Full.Visibility = Visibility.Visible;
    }
 
    void pic_MouseLeave(object sender, MouseEventArgs e)
    {
      //繼續(xù)動(dòng)畫(huà)
      storyboard.Resume();
    }
 
    void pic_MouseEnter(object sender, MouseEventArgs e)
    {
      //暫停動(dòng)畫(huà)
      storyboard.Pause();
    }
 
    private void img_Full_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
      //隱藏放大圖片
      img_Full.Visibility = Visibility.Collapsed;
    }
 
    private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e)
    {
      //動(dòng)畫(huà)根據(jù)屏幕大小改變而改變
      Resize();
    }
}

同時(shí)還有一個(gè)UserControl用來(lái)承載圖片代碼如下:

<Canvas x:Name="LayoutRoot" Background="White">
  <Image x:Name="photo" Width="320" Height="240" Stretch="UniformToFill" Margin="10" />
</Canvas>

C#:

public partial class UC_pic : UserControl
  {
    public UC_pic()
    {
      InitializeComponent();
    }
    private string _imgUrl;
    public string ImageUrl
    {
      get { return this._imgUrl; }
      set { 
        //設(shè)置圖片資源屬性
        this._imgUrl = value;
        Uri uri = new Uri(value, UriKind.Relative);
        BitmapImage bitimg = new BitmapImage(uri);
        this.photo.Source = bitimg;
      }
    }
  }

這樣就完成了跑馬燈的效果,如圖:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。

上一篇:Silverlight實(shí)現(xiàn)星星閃爍動(dòng)畫(huà)

欄    目:C#教程

下一篇:實(shí)例詳解C#實(shí)現(xiàn)http不同方法的請(qǐng)求

本文標(biāo)題:Silverlight實(shí)現(xiàn)跑馬燈動(dòng)畫(huà)

本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/5149.html

網(wǎng)頁(yè)制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語(yǔ)言數(shù)據(jù)庫(kù)服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有