private void Button_Click(object sender, RoutedEventArgs e) { if (StartOrStop.Content.Equals("开始")) { gifImage.StartAnimate(); StartOrStop.Content = "结束"; } else { gifImage.StopAnimate(); StartOrStop.Content = "开始"; } }
/// <summary> /// 初始化背景 /// </summary> private void InitBackground() { if (MainWindow.VM.BackType == LKBackGround.BackGroundType.Image) { ImgCount = GetImageFileCount(MainWindow.VM.FilePath); if (ImgCount >= 1) { IMG = new Image(); Binding bind = new Binding() { Source = MainWindow.VM, Path = new PropertyPath("LKImagesource"), Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; IMG.SetBinding(Image.SourceProperty, bind); this.content.Content = IMG; storyboard.Completed += Storyboard_Completed; if (ImgCount > 1) { LoopToPalyAnimation(); } } } else if (MainWindow.VM.BackType == LKBackGround.BackGroundType.Gif) { GifImage gifImage = new GifImage(MainWindow.VM.FilePath); gifImage.Stretch = Stretch.Fill; this.content.Content = gifImage; gifImage.StartAnimate(); } else if (MainWindow.VM.BackType == LKBackGround.BackGroundType.Video) { MediaElement media = new MediaElement(); media.Source = new Uri(MainWindow.VM.FilePath); media.LoadedBehavior = MediaState.Manual; media.Play(); //填充整个屏幕 media.Stretch = Stretch.Fill; this.content.Content = media; //当媒体播放结束时重复播放 media.MediaEnded += (s, e) => { media.Position = TimeSpan.Zero; media.Play(); }; } }