private void calculatePosition() { if (isCalculate) { return; } isCalculate = true; double offset = 0; for (int i = 0; i < lsStack.Children.Count; i++) { ImgIfo info = lsImgInfo[i]; info.startOffset = offset; offset += info.imgView.ActualWidth; info.endOffset = offset; info.position = i; info.isLucky = false; } double neededwidth = scroll.ViewportWidth; int posadd = 0; while (neededwidth > 0) { neededwidth -= lsImgInfo[posadd].imgView.ActualWidth; Image img = new Image(); BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.DecodePixelHeight = 400; bi.UriSource = new Uri(lsImgInfo[posadd].path); bi.EndInit(); img.Source = bi; lsStack.Children.Add(img); posadd++; } }
public SpinerWindow(string lgpth, String bg, List <String> imgsPth, int size) { InitializeComponent(); BitmapImage bi = new BitmapImage(new Uri(bg)); background.ImageSource = bi; lsImgInfo = new List <ImgIfo>(); foreach (var pth in imgsPth) { Image img = new Image(); BitmapImage bmi = new BitmapImage(); bmi.BeginInit(); bmi.DecodePixelHeight = 300; bmi.UriSource = new Uri(pth); bmi.EndInit(); img.Source = bmi; lsStack.Children.Add(img); ImgIfo info = new ImgIfo(); info.path = pth; info.imgView = img; lsImgInfo.Add(info); } //gen grid opacity totalImgSize = size; grids = new List <Grid>(); gridsbinding = new List <ImgIfo>(); for (int i = 0; i < totalImgSize; i++) { grid.ColumnDefinitions.Add(new ColumnDefinition()); grid.RowDefinitions.Add(new RowDefinition()); } int temp = 0; for (int i = 0; i < totalImgSize; i++) { for (int j = 0; j < totalImgSize; j++) { Grid gridElement = new Grid(); gridElement.Background = Brushes.Black; gridElement.Opacity = 0.5; gridElement.SetValue(Grid.RowProperty, i); gridElement.SetValue(Grid.ColumnProperty, j); gridElement.SetValue(Grid.RowSpanProperty, 1); gridElement.SetValue(Grid.ColumnSpanProperty, 1); grids.Add(gridElement); grid.Children.Add(gridElement); if (i >= (totalImgSize / 4) && i < (totalImgSize * 3 / 4) && j >= (totalImgSize / 4) && j < (totalImgSize * 3 / 4)) //mainImage { gridsbinding.Add(null); } else { gridsbinding.Add(lsImgInfo[temp]); temp = (temp + 1) % lsImgInfo.Count; } } } mainPath = null; scroll.ScrollChanged += Scroll_ScrollChanged; rotateAnimation = new DoubleAnimation(); storyboard = new Storyboard(); storyboard.Children.Add(rotateAnimation); Storyboard.SetTarget(rotateAnimation, this); Storyboard.SetTargetProperty(rotateAnimation, new PropertyPath(SpinerWindow.ScrollOffsetProperty)); // Attached dependency property //rotateAnimation.Completed += RotateAnimation_Completed; rotateAnimation.AutoReverse = true; rotateAnimation.RepeatBehavior = RepeatBehavior.Forever; btnMode = 0; rotateMode = -1; countDownTimer = new DispatcherTimer(); countDownTimer.Tick += CountDownTimer_Tick; countDownTimer.Interval = TimeSpan.FromSeconds(1); countDownValue = 5; //player = new SoundPlayer(@"C:\Users\tuenh\Downloads\tick.wav"); //player.Load(); //isplayingSound = false; rotateTimer = new DispatcherTimer(); rotateTimer.Tick += RotateTimer_Tick; rotateTimer.Interval = TimeSpan.FromMilliseconds(50); curentPos = 0; nextPos = 0; flickerAnimation = new DoubleAnimation(); flickerAnimation.From = 0; flickerAnimation.To = 1; flickerAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(50)); flickerAnimation.AutoReverse = true; flickerAnimation.RepeatBehavior = RepeatBehavior.Forever; logoPath = lgpth; BitmapImage logobmp = new BitmapImage(); logobmp.BeginInit(); logobmp.DecodePixelHeight = 400; logobmp.UriSource = new Uri(logoPath); logobmp.EndInit(); mainImg.Source = logobmp; }