/// <summary> /// Updates the margin used for animating the Window Title when the window loads. /// </summary> /// <param name="tb">TextBlock which displays the window title</param> /// <param name="margin">New Margin</param> private void UpdateTriggerMargin(TextBlock tb, Thickness margin) { if ((tb.Triggers == null) || (tb.Triggers.Count == 0)) { return; } foreach (EventTrigger trigger in tb.Triggers) { if (trigger.RoutedEvent.Name == "TargetUpdated") { if ((trigger.Actions != null) && (trigger.Actions.Count > 0)) { BeginStoryboard bsb = trigger.Actions[0] as BeginStoryboard; if (bsb != null) { foreach (Timeline timeLine in bsb.Storyboard.Children) { ThicknessAnimation anim = timeLine as ThicknessAnimation; if (anim != null) { Thickness startThickness = new Thickness(margin.Left + 200, margin.Top, margin.Right, margin.Bottom); anim.SetValue(ThicknessAnimation.FromProperty, startThickness); anim.SetValue(ThicknessAnimation.ToProperty, margin); } } } } } } }
public void RollIn(ref object sender, string borderName) { thicknessAnimation.SetValue(Storyboard.TargetNameProperty, borderName); thicknessAnimation.From = outsideScreen; thicknessAnimation.To = insideScreen; storyboard.Children.Add(thicknessAnimation); storyboard.Begin(mainWindow); }
private void listicon_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { CentralPix = 0; var previousmargin = listicon.Margin; var nextmargin = previousmargin; double divbyFive = listicon.SelectedIndex / 5; int ligneindex = Convert.ToInt32(Math.Floor(divbyFive)); nextmargin.Top = CentralPix - (ligneindex * itemheight); var sb = new Storyboard(); var ta = new ThicknessAnimation(); ta.BeginTime = new TimeSpan(0); ta.SetValue(Storyboard.TargetNameProperty, "listicon"); Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty)); ta.From = previousmargin; ta.To = nextmargin; ta.Duration = new Duration(TimeSpan.FromMilliseconds(500)); sb.Children.Add(ta); sb.Begin(this); } catch (Exception ex) { //throw; } }
public Battle(Player p) { InitializeComponent(); rand = new Random(); p1 = p; IsEnd = false; List <Pokemon> playerPokemon = p1.GetPokemons(); PlayerPokemonList.ItemsSource = p1.GetPokemons(); GridChangePokemon.Visibility = Visibility.Visible; // Animation of Switch Box var sb = new Storyboard(); var ta = new ThicknessAnimation(); ta.BeginTime = new TimeSpan(0); ta.SetValue(Storyboard.TargetNameProperty, "GridChangePokemon"); Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty)); ta.From = new Thickness(0, 0, 0, -1000); ta.To = new Thickness(0, 0, 0, 100); ta.Duration = new Duration(TimeSpan.FromSeconds(0.3)); sb.Children.Add(ta); sb.Begin(this); bgPic.Opacity = 0.5; }
public void AppsMenuWin_Loaded(object sender, RoutedEventArgs e) { gridMain.Margin = new Thickness(this.Left - this.Width, gridMain.Margin.Top, gridMain.Margin.Right, gridMain.Margin.Bottom); foreach (string file in Directory.GetFiles(Environment.GetEnvironmentVariable("appdata") + @"\Microsoft\Windows\Start Menu\Programs", "*.lnk", SearchOption.AllDirectories)) { try { ImageSource icn; icn = winutils.GetIcon(file); if (icn == null) { break; } LBItem itm = new LBItem { FileIcon = icn, FileName = System.IO.Path.GetFileNameWithoutExtension(file), FullPath = file }; this.DataContext = itm; appsList.Items.Add(itm); } catch { MessageBox.Show("Error while adding " + file + "to the list.", "error", MessageBoxButton.OK, MessageBoxImage.Error); } } var sb = new Storyboard(); var ta = new ThicknessAnimation(); ta.BeginTime = new TimeSpan(0); ta.SetValue(Storyboard.TargetNameProperty, "gridMain"); Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty)); ta.From = new Thickness(gridMain.Margin.Left, gridMain.Margin.Top, gridMain.Margin.Right, gridMain.Margin.Bottom); ta.To = new Thickness(this.Left + 8, gridMain.Margin.Top, gridMain.Margin.Right, gridMain.Margin.Bottom); ta.Duration = new Duration(TimeSpan.FromSeconds(1)); sb.Children.Add(ta); sb.Begin(this); }
private void SwitchPokemon(object sender, RoutedEventArgs e) { GridChangePokemon.Visibility = Visibility.Visible; // Animation of Switch Box var sb = new Storyboard(); var ta = new ThicknessAnimation(); ta.BeginTime = new TimeSpan(0); ta.SetValue(Storyboard.TargetNameProperty, "GridChangePokemon"); Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty)); if (!switchingPokemon) { ta.From = new Thickness(0, 0, 0, -300); ta.To = new Thickness(0, 0, 0, -10); } else { ta.From = new Thickness(0, 0, 0, -10); ta.To = new Thickness(0, 0, 0, -300); } ta.Duration = new Duration(TimeSpan.FromSeconds(0.3)); switchingPokemon = !switchingPokemon; sb.Children.Add(ta); sb.Begin(this); }
private void ButtonClickSelectPokemon(object sender, RoutedEventArgs e) { var button = (Button)sender; Pokemon selectedPkm = button.DataContext as Pokemon; if (selectedPkm.GetHP == 0) { MessageBox.Show("Your Pokemon is Out of Health! Come again some time."); Program.status = 0; this.NavigationService.GoBack(); } var sb = new Storyboard(); var ta = new ThicknessAnimation(); ta.BeginTime = new TimeSpan(0); ta.SetValue(Storyboard.TargetNameProperty, "GridChangePokemon"); Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty)); ta.From = new Thickness(0, 0, 0, 100); ta.To = new Thickness(0, 0, 0, -1000); ta.Duration = new Duration(TimeSpan.FromSeconds(0.3)); sb.Children.Add(ta); sb.Begin(this); GridChangePokemon.Visibility = Visibility.Hidden; battleGym = new BattleGym(p1.GetPokemons().Find(x => x.Id == selectedPkm.Id), generateRandomBoss(), Win, Lose); StatusMessage.Text = "Your turn! Pick your move"; setBoss(); usePokemon(); restcount = 0; restTimer.Tick += restTimer_Tick; restTimer.Interval = TimeSpan.FromSeconds(1); restTimer.Start(); bgPic.Opacity = 1; }
private void listicon_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { var splitbyheight = this.ActualWidth / 8; CentralPix = 640; int itemwidht = 320; var previousmargin = listicon.Margin; var nextmargin = previousmargin; //nextmargin.Left = -itemwidht * listicon.SelectedIndex; nextmargin.Left = CentralPix - (listicon.SelectedIndex * itemwidht); var sb = new Storyboard(); var ta = new ThicknessAnimation(); ta.BeginTime = new TimeSpan(0); ta.SetValue(Storyboard.TargetNameProperty, "listicon"); Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty)); ta.From = previousmargin; ta.To = nextmargin; ta.Duration = new Duration(TimeSpan.FromMilliseconds(500)); sb.Children.Add(ta); sb.Begin(this); } catch (Exception ex) { //throw; } }
private void playDefaultMusic() { if (System.IO.File.Exists("default.mp3")) { playingMedia = new Media(AppDomain.CurrentDomain.BaseDirectory + "/default.mp3", "*"); this.DataContext = playingMedia; playingMedia.media.Volume = volume.Value / 100; var sb = new Storyboard(); var ta = new ThicknessAnimation(); ta.BeginTime = new TimeSpan(0); ta.SetValue(Storyboard.TargetNameProperty, txtPlayingTitle.Name); Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty)); ta.From = new Thickness(0, 0, 0, 0); var a = txtPlayingTitle; ta.To = new Thickness(-200, 0, 0, 0); ta.Duration = new Duration(TimeSpan.FromSeconds(3)); ta.AutoReverse = true; ta.RepeatBehavior = RepeatBehavior.Forever; sb.Children.Add(ta); sb.Begin(this); } }
private void SetActionTriggers() { var width = _slidingPage.ActualWidth; EnterActions.Clear(); ExitActions.Clear(); var enterStoryboard = new Storyboard(); var enterMarginAnimation = new ThicknessAnimation(new Thickness(width, 0, -width, 0), new Thickness(0), new Duration(TimeSpan.FromSeconds(.75))) { DecelerationRatio = .9 }; enterMarginAnimation.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("(FrameworkElement.Margin)")); enterStoryboard.Children.Add(enterMarginAnimation); var enterOpacityAnimation = new DoubleAnimation(0, 1, new Duration(TimeSpan.FromSeconds(.25))); enterOpacityAnimation.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("(UIElement.Opacity)")); enterStoryboard.Children.Add(enterOpacityAnimation); var enterVisibilityAnimation = new EnterVisibilityAnimation(); enterStoryboard.Children.Add(enterVisibilityAnimation); EnterActions.Add(new BeginStoryboard { Storyboard = enterStoryboard }); var exitStoryboard = new Storyboard(); var exitMarginAnimation = new ThicknessAnimation(new Thickness(-width, 0, width, 0), new Duration(TimeSpan.FromSeconds(.5))) { AccelerationRatio = .9 }; exitMarginAnimation.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("(FrameworkElement.Margin)")); exitStoryboard.Children.Add(exitMarginAnimation); var exitOpacityAnimation = new DoubleAnimation(0, new Duration(TimeSpan.FromSeconds(.5))); exitOpacityAnimation.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("(UIElement.Opacity)")); exitStoryboard.Children.Add(exitOpacityAnimation); var exitVisibilityAnimation = new ExitVisibilityAnimation(); exitStoryboard.Children.Add(exitVisibilityAnimation); ExitActions.Add(new BeginStoryboard { Storyboard = exitStoryboard }); }
private void AnimationClick(Button srcButton) { Thickness margin; Button animationButton; if (srcButton.Name == "FavouriteButton") { margin = new Thickness(85, 455, -200, -405); animationButton = FavouriteAnimationButton; } else if (srcButton.Name == "SkipButton") { margin = new Thickness(225, 455, -335, -405); animationButton = SkippedAnimationButton; } else { margin = new Thickness(500, 455, -335, -405); animationButton = DislikedAnimationButton; } Storyboard sb = FindResource("ClickAnimation") as Storyboard; animationButton.Visibility = Visibility.Visible; var toMargin = new Thickness { Left = margin.Left, Right = margin.Right, Top = margin.Top - 100, Bottom = margin.Bottom }; var ta = new ThicknessAnimation { BeginTime = new TimeSpan(0), From = margin, To = toMargin, Duration = new Duration(TimeSpan.FromSeconds(0.55)) }; ta.SetValue(Storyboard.TargetNameProperty, "AnimationButton"); Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty)); sb.Children.Add(ta); Storyboard.SetTarget(sb, animationButton); DispatcherTimer timer = new DispatcherTimer(); timer.Tick += AnimationComplete; timer.Interval = TimeSpan.FromSeconds(0.15); sb.Begin(); timer.Start(); }
private void UpdateMoveDuration(Storyboard sb, Duration duration) { if (sb != null) { foreach (Timeline timeline in sb.Children) { ThicknessAnimation anim = timeline as ThicknessAnimation; if (anim != null) { anim.SetValue(ThicknessAnimation.DurationProperty, duration); } } } }
private void UpdateFadeOutDistance(Storyboard sb, Thickness thickness) { if (sb != null) { foreach (Timeline timeline in sb.Children) { ThicknessAnimation anim = timeline as ThicknessAnimation; if (anim != null) { anim.SetValue(ThicknessAnimation.ToProperty, thickness); } } } }
/// <summary> /// Simple function that will take care of hiding the node settings view /// </summary> private void HideConfig() { Storyboard sb = new Storyboard(); ThicknessAnimation thicknessAnimation = new ThicknessAnimation(); thicknessAnimation.SetValue(Storyboard.TargetProperty, NodeSettings); Storyboard.SetTargetProperty(thicknessAnimation, new PropertyPath(MarginProperty)); thicknessAnimation.From = new Thickness(0, 0, 0, 0); thicknessAnimation.To = new Thickness(0, 0, -210, 0); thicknessAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(500)); sb.Children.Add(thicknessAnimation); sb.Begin(this); }
static public Storyboard MoveAnimation(this Block block, int from_x, int from_y, int to_x, int to_y) { var animation = new ThicknessAnimation { To = ToTarget(block, from_x, from_y, to_x, to_y), Duration = converter.TimeConverter.Times(2), AccelerationRatio = 0.6 }; block.traveller.BeginAnimation(FrameworkElement.MarginProperty, animation); var storyboard = new Storyboard(); storyboard.Children.Add(animation); animation.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("Margin")); return(storyboard); }
/// <summary> /// https://stackoverflow.com/questions/10181245/how-can-i-animate-the-margin-of-a-stackpanel-with-a-storyboard /// </summary> /// <param name="newMargin"></param> private void ChangeDashboardContentMargin(Thickness newMargin) { var sb = new Storyboard(); var ta = new ThicknessAnimation(); ta.BeginTime = new TimeSpan(0); ta.SetValue(Storyboard.TargetNameProperty, "DashboardHost"); Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty)); ta.From = DashboardContentMargin; ta.To = newMargin; ta.Duration = new Duration(TimeSpan.FromMilliseconds(500)); sb.Children.Add(ta); sb.Begin(this); DashboardContentMargin = newMargin; }
/// <summary> /// Callback when some control element is double clicked that will show the settings for selected control /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void object_MouseDoubleClick(object sender, MouseButtonEventArgs e) { Storyboard sb = new Storyboard(); ThicknessAnimation thicknessAnimation = new ThicknessAnimation(); thicknessAnimation.SetValue(Storyboard.TargetProperty, NodeSettings); Storyboard.SetTargetProperty(thicknessAnimation, new PropertyPath(MarginProperty)); thicknessAnimation.From = new Thickness(0, 0, -210, 0); thicknessAnimation.To = new Thickness(0, 0, 0, 0); thicknessAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(500)); NodeSettings.Visibility = Visibility.Visible; Messenger.Default.Send(sender, "showConfig"); sb.Children.Add(thicknessAnimation); sb.Begin(this); }
private void getLastSongPlaying(string path, string playlistName, string index) { if (path != "empty" || System.IO.File.Exists(path)) { playingMedia = new Media(path, playlistName); this.DataContext = playingMedia; playingMedia.media.Volume = volume.Value / 100; int res = 0; if (Int32.TryParse(index, out res)) { playingSongIndex = res; } var sb = new Storyboard(); var ta = new ThicknessAnimation(); ta.BeginTime = new TimeSpan(0); ta.SetValue(Storyboard.TargetNameProperty, txtPlayingTitle.Name); Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty)); ta.From = new Thickness(0, 0, 0, 0); var a = txtPlayingTitle; ta.To = new Thickness(-200, 0, 0, 0); ta.Duration = new Duration(TimeSpan.FromSeconds(3)); ta.AutoReverse = true; ta.RepeatBehavior = RepeatBehavior.Forever; sb.Children.Add(ta); sb.Begin(this); } else { playDefaultMusic(); } }
/// <summary> /// 1:This is my "play" button, this uses StoryBoard and Thickness animations so that once the button is pressed the colorful bars move out of the way of the play area. /// 2:A Doubleanimation is used to "draw" the play area. It changes the opacity of the buttons from 0 to 1. /// 3: Once the buttons been pressed the "play" button becomes dissabled. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button_Click_2(object sender, RoutedEventArgs e) { #region The animations for the sticks are here //Animation for stick 1 var sb = new Storyboard(); var ta = new ThicknessAnimation(); ta.BeginTime = new TimeSpan(0); ta.SetValue(Storyboard.TargetNameProperty, "stick1"); Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty)); ta.From = new Thickness(94, 0, 182, 0); ta.To = new Thickness(94, 0, 500, 0); ta.Duration = new Duration(TimeSpan.FromSeconds(1)); sb.Children.Add(ta); sb.Begin(this); //Stick2 animation ta.SetValue(Storyboard.TargetNameProperty, "stick2"); Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty)); ta.From = new Thickness(86, 0, -93, 0); ta.To = new Thickness(86, 0, 500, 0); ta.Duration = new Duration(TimeSpan.FromSeconds(1)); sb.Children.Add(ta); sb.Begin(this); //Stick3 animation ta.SetValue(Storyboard.TargetNameProperty, "stick3"); Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty)); ta.From = new Thickness(91, 0, 127, 0); ta.To = new Thickness(91, 0, 500, 0); ta.Duration = new Duration(TimeSpan.FromSeconds(1)); sb.Children.Add(ta); sb.Begin(this); //Stick4 animation ta.SetValue(Storyboard.TargetNameProperty, "stick4"); Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty)); ta.From = new Thickness(94, 0, 296, 0); ta.To = new Thickness(94, 0, 500, 0); ta.Duration = new Duration(TimeSpan.FromSeconds(1)); sb.Children.Add(ta); sb.Begin(this); //Stick5 animation ta.SetValue(Storyboard.TargetNameProperty, "stick5"); Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty)); ta.From = new Thickness(328, 0, -113, 0); ta.To = new Thickness(328, 0, 500, 0); ta.Duration = new Duration(TimeSpan.FromSeconds(1)); sb.Children.Add(ta); sb.Begin(this); //Stick6 animation ta.SetValue(Storyboard.TargetNameProperty, "stick6"); Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty)); ta.From = new Thickness(47, 0, 74, 0); ta.To = new Thickness(47, 0, 500, 0); ta.Duration = new Duration(TimeSpan.FromSeconds(1)); sb.Children.Add(ta); sb.Begin(this); //Stick7 animation ta.SetValue(Storyboard.TargetNameProperty, "stick7"); Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty)); ta.From = new Thickness(298, 0, 1, 0); ta.To = new Thickness(298, 0, 500, 0); ta.Duration = new Duration(TimeSpan.FromSeconds(1)); sb.Children.Add(ta); sb.Begin(this); //Stick8 animation ta.SetValue(Storyboard.TargetNameProperty, "stick8"); Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty)); ta.From = new Thickness(300, 0, -113, 0); ta.To = new Thickness(300, 0, 500, 0); ta.Duration = new Duration(TimeSpan.FromSeconds(1)); sb.Children.Add(ta); sb.Begin(this); //Stick 9 ta.SetValue(Storyboard.TargetNameProperty, "stick9"); Storyboard.SetTargetProperty(ta, new PropertyPath(MarginProperty)); ta.From = new Thickness(47, 0, -165, 0); ta.To = new Thickness(47, 0, 500, 0); ta.Duration = new Duration(TimeSpan.FromSeconds(1)); sb.Children.Add(ta); sb.Begin(this); #endregion #region Show the game area DoubleAnimation da = new DoubleAnimation(); da.From = 0; da.To = 1; da.Duration = new Duration(TimeSpan.FromSeconds(2)); Button0.BeginAnimation(OpacityProperty, da); Button1.BeginAnimation(OpacityProperty, da); Button2.BeginAnimation(OpacityProperty, da); Button3.BeginAnimation(OpacityProperty, da); Button4.BeginAnimation(OpacityProperty, da); Button5.BeginAnimation(OpacityProperty, da); Button6.BeginAnimation(OpacityProperty, da); Button7.BeginAnimation(OpacityProperty, da); Button8.BeginAnimation(OpacityProperty, da); #endregion #region disable the play button PlayButton.IsEnabled = false; PlayButton.Background = Brushes.Gray; #endregion }