コード例 #1
0
        public void CollapseAnimation()
        {
            DoubleAnimation da = new DoubleAnimation();

            da.From = stackPanel.ActualHeight;
            da.To   = 0;
            Duration duration = new Duration(TimeSpan.FromMilliseconds(300));

            da.Duration = duration;
            stackPanel.BeginAnimation(HeightProperty, da);
        }
コード例 #2
0
ファイル: WndEscenari.xaml.cs プロジェクト: fxbp/ReunioSocial
        private void Transicio(StackPanel sp, Direccio dir)
        {
            Storyboard         story          = new Storyboard();
            ThicknessAnimation animacioStack1 = new ThicknessAnimation();
            Thickness          marginOri      = sp.Margin;
            Thickness          margin         = RetornaDireccioMargin(dir);



            story.Children.Add(animacioStack1);

            //sp.SetValue(Grid.ZIndexProperty, 10);
            animacioStack1.From         = marginOri;
            animacioStack1.To           = margin;
            animacioStack1.Duration     = TimeSpan.FromSeconds(SEGONSPAUSA / 2);
            animacioStack1.FillBehavior = FillBehavior.HoldEnd;

            Storyboard.SetTarget(animacioStack1, sp);
            Storyboard.SetTargetProperty(animacioStack1, new PropertyPath(Grid.MarginProperty));

            story.Begin();
            Pausa(SEGONSPAUSA);
            // Thread.Sleep(TimeSpan.FromSeconds(SEGONSPAUSA));


            sp.BeginAnimation(Grid.MarginProperty, null);
        }
コード例 #3
0
        private void Bd_MouseEnter(object sender, MouseEventArgs e, StackPanel stats)
        {
            fadeOutBorder.From = ((Border)sender).Opacity;
            fadeInText.From    = stats.Opacity;

            stats.BeginAnimation(OpacityProperty, fadeInText);
            ((Border)sender).BeginAnimation(OpacityProperty, fadeOutBorder);
        }
コード例 #4
0
 /// <summary>
 /// 歌词滚动。滚动到指定歌词索引位置
 /// </summary>
 /// <param name="indexSite">第几句歌词索引位置(歌词第0句是起始句)</param>
 public static void scrollLyric(int indexSite)
 {
     Canvas.SetTop(canvasFocusLyric, lyricCanvas.ActualHeight / 2 - lyricTextBlockHeight);
     topOffset = lyricCanvas.ActualHeight / 2 - indexSite * lyricTextBlockHeight - lyricTextBlockHeight;
     lyricPanelScrollAni.To       = topOffset;
     lyricPanelScrollAni.Duration = new Duration(TimeSpan.Parse("0:0:0.5"));
     commonLyricStackPanel.BeginAnimation(Canvas.TopProperty, lyricPanelScrollAni);
 }
コード例 #5
0
        private void HandleNotebookIconAction(StackPanel container)
        {
            // setup anim
            container.MouseDown += (sender, args) =>
            {
                args.Handled = true;
                var disappearAnimation = new DoubleAnimation
                {
                    From           = 1,
                    To             = 0.2,
                    Duration       = new Duration(TimeSpan.FromSeconds(0.30)),
                    EasingFunction = new PowerEase()
                    {
                        EasingMode = EasingMode.EaseOut,
                        Power      = 1.5
                    },
                    AutoReverse = true
                };
                var translateAnimation = new DoubleAnimation
                {
                    From           = 0,
                    To             = 100,
                    Duration       = new Duration(TimeSpan.FromSeconds(0.20)),
                    EasingFunction = new PowerEase()
                    {
                        EasingMode = EasingMode.EaseOut,
                        Power      = 2
                    },
                };
                translateAnimation.Completed += (o, eventArgs) =>
                {
                    Task.Run(async() =>
                    {
                        await Task.Delay(150);
                        await Dispatcher.InvokeAsync(Reset);
                    });
                };
                var translateTransform = new TranslateTransform();
                MainCanvas.RenderTransform = translateTransform;
                translateTransform.BeginAnimation(TranslateTransform.XProperty, translateAnimation);
                MainCanvas.BeginAnimation(OpacityProperty, disappearAnimation);
            };
            //cursor
            ChangeMouseCursorToSelect(container);

            // run animation
            container.BeginAnimation(OpacityProperty, new DoubleAnimation
            {
                From           = 0.0,
                To             = 1.0,
                Duration       = new Duration(TimeSpan.FromSeconds(0.5)),
                EasingFunction = new SineEase()
                {
                    EasingMode = EasingMode.EaseIn,
                }
            });
        }
コード例 #6
0
ファイル: SettingView.xaml.cs プロジェクト: kchang06/GFAlarm
        /// <summary>
        /// 그룹박스 여닫기
        /// </summary>
        /// <param name="name"></param>
        /// <param name="expand"></param>
        private void SetListBoxVisible(string name, bool expand = true)
        {
            StackPanel listbox = this.FindName(string.Format("{0}ListBox", name)) as StackPanel;

            if (listbox != null)
            {
                listbox.BeginAnimation(StackPanel.HeightProperty, null);

                Animations.ChangeHeight.From = expand == true ? 0 : listbox.ActualHeight;
                Animations.ChangeHeight.To   = expand == true ? listbox.ActualHeight : 0;

                listbox.BeginAnimation(StackPanel.HeightProperty, Animations.ChangeHeight);
            }
            PackIconMaterial arrow = this.FindName(string.Format("{0}GroupBox_Arrow", name)) as PackIconMaterial;

            if (arrow != null)
            {
                arrow.Kind = expand == true ? PackIconMaterialKind.ChevronDown : PackIconMaterialKind.ChevronUp;
            }
        }
コード例 #7
0
        private void Bd_MouseLeave(object sender, MouseEventArgs e, StackPanel stats)
        {
            if (stats.Children[0].IsMouseOver || stats.Children[1].IsMouseOver)
            {
                return;
            }

            fadeInBorder.From = ((Border)sender).Opacity;
            fadeOutText.From  = stats.Opacity;

            stats.BeginAnimation(OpacityProperty, fadeOutText);
            ((Border)sender).BeginAnimation(OpacityProperty, fadeInBorder);
        }
コード例 #8
0
        /// <summary>
        ///  Создает горизонтальную атаку
        /// </summary>
        /// <param name="scale">Размер</param>
        /// <param name="top">Отступ</param>
        /// <param name="moveDragon">Конечная точка перемещения врага</param>
        /// <returns>Враг</returns>
        private StackPanel DragonBallAttack(int scale, double top, double moveDragon)
        {
            StackPanel dragonAttack = new StackPanel
            {
                Width  = gameApp.dragonAttacks.Width,
                Height = gameApp.dragonAttacks.Height,

                RenderTransformOrigin = new Point(0.5, 0.5),
                Orientation           = Orientation.Horizontal
            };

            dragonAttackObj[0] = new Image
            {
                Width   = gameApp.dragon.Width,
                Height  = gameApp.dragon.Height,
                Stretch = System.Windows.Media.Stretch.None,
                Margin  = gameApp.dragon.Margin
            };

            var image = new BitmapImage();

            image.BeginInit();
            image.UriSource = new Uri("Images/HorizAttack.gif", UriKind.RelativeOrAbsolute);
            image.EndInit();

            ImageBehavior.SetAnimatedSource((dragonAttackObj[0] as Image), image);
            Canvas.SetLeft(dragonAttack, 0);

            dragonAttackObj[1] = new Rectangle
            {
                Width  = gameApp.lich.Width - 20,
                Fill   = gameApp.lich.Fill,
                Margin = gameApp.lich.Margin,

                Visibility = Visibility.Hidden
            };

            showLich();

            dragonAttack.Children.Add(dragonAttackObj[0]);
            dragonAttack.Children.Add(dragonAttackObj[1]);

            dragonAttack.RenderTransform = new ScaleTransform(scale, 1);
            Canvas.SetTop(dragonAttack, top);

            dragonAttack.BeginAnimation(Canvas.TopProperty, SetAnimationDragon(dragonAttack, moveDragon));

            timerCheckHitHoriz = CheckToHitHorizontAttack(dragonAttack);
            return(dragonAttack);
        }
コード例 #9
0
ファイル: QuickJumper.cs プロジェクト: erimus/BoytrixWpf
        // Depending on which key was pressed moves MetroStackPanel so that
        // the WrapPanel containing required tiles is in view.
        public static void ShiftStackPanel(string letter, StackPanel metroStackPanel)
        {
            if (WrapPanelDi.ContainsKey(letter.ToLower()))
            {
                DoubleAnimationUsingKeyFrames doubleAnim = new DoubleAnimationUsingKeyFrames();
                double newX = WrapPanelDi[letter.ToLower()];
                doubleAnim.Duration = TimeSpan.FromMilliseconds(1800);

                doubleAnim.KeyFrames.Add(new SplineDoubleKeyFrame(-newX, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1)), new KeySpline(0.161, 0.079, 0.008, 1)));
                doubleAnim.FillBehavior = FillBehavior.HoldEnd;
                metroStackPanel.BeginAnimation(Canvas.LeftProperty, doubleAnim);
                doubleAnim.KeyFrames.Clear();
            }
        }
コード例 #10
0
        private void CreateMenuAnimation(StackPanel animatingPanel)
        {
            DoubleAnimation heightAnimation = new DoubleAnimation();

            heightAnimation.Duration       = TimeSpan.FromSeconds(0.5);
            heightAnimation.EasingFunction = new CubicEase();

            if (animatingPanel.Height == 0)
            {
                heightAnimation.From = 0d;
                heightAnimation.To   = GetStackPanelHeight(animatingPanel);
            }
            else
            {
                heightAnimation.From = GetStackPanelHeight(animatingPanel);
                heightAnimation.To   = 0d;
            }

            animatingPanel.BeginAnimation(StackPanel.HeightProperty, heightAnimation);
        }
コード例 #11
0
        private bool CloseOpenedPanes(bool paneOpened, Rectangle SecondaryNavPaneRectangle, Image ButtonIcon, StackPanel panel)
        {
            if (paneOpened)
            {
                PageCV.SecondaryNavPaneColumn.Width = new GridLength(0);
                RootGridSecondaryPaneCol.Width      = new GridLength(0);

                Duration        duration        = new Duration(TimeSpan.FromMilliseconds(100));
                DoubleAnimation doubleanimation = new DoubleAnimation(0, duration);
                DoubleAnimation windowAnimation = new DoubleAnimation(this.Width - 185, duration);

                SecondaryNavPaneRectangle.BeginAnimation(Rectangle.WidthProperty, doubleanimation);
                this.BeginAnimation(MainWindow.WidthProperty, windowAnimation);
                AppBarSecondaryNavPane.BeginAnimation(Rectangle.WidthProperty, doubleanimation);
                panel.BeginAnimation(StackPanel.WidthProperty, doubleanimation);

                ButtonIcon.Source = new BitmapImage(new Uri(@"icon/icons8-Forward.png", UriKind.Relative));

                paneOpened = false;
            }
            return(paneOpened);
        }
コード例 #12
0
        public static void ShowToast(Grid baseGrid, string message)
        {
            gridCount++;

            StackPanel grid = new StackPanel();

            grid.Width               = 200;
            grid.Height              = 40;
            grid.Background          = new System.Windows.Media.SolidColorBrush(Colors.Gray);
            grid.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
            grid.VerticalAlignment   = System.Windows.VerticalAlignment.Bottom;
            grid.Margin              = new Thickness(0, 0, 0, 30);


            TextBlock text = new TextBlock();

            text.Text = message;
            text.VerticalAlignment   = VerticalAlignment.Center;
            text.HorizontalAlignment = HorizontalAlignment.Center;
            text.FontSize            = 22;

            grid.Children.Add(text);

            baseGrid.Children.Add(grid);

            DispatcherTimer timer = new DispatcherTimer();

            timer.Interval = new TimeSpan(0, 0, 3);
            timer.Tick    += (sender, args) =>
            {
                var anim = new DoubleAnimation(0, (Duration)TimeSpan.FromSeconds(1));
                grid.BeginAnimation(UIElement.OpacityProperty, anim);
                anim.Completed += (s, _) => baseGrid.Children.Remove(grid);
                timer.Stop();
            };
            timer.Start();
        }
コード例 #13
0
        public Start()
        {
            WindowStartupLocation = WindowStartupLocation.CenterScreen;
            InitializeComponent();
            StackPanel myStackPanel = new StackPanel();

            myStackPanel.Height = ActualHeight;
            DoubleAnimation myDoubleAnimation = new DoubleAnimation();

            myDoubleAnimation.From        = 700;
            myDoubleAnimation.To          = 0;
            myDoubleAnimation.Duration    = new Duration(TimeSpan.FromSeconds(3));
            myDoubleAnimation.AutoReverse = false;
            myStackPanel.BeginAnimation(StackPanel.HeightProperty, myDoubleAnimation);
            SolidColorBrush myBrush = new SolidColorBrush();

            myBrush.Color           = Colors.DarkCyan;
            myStackPanel.Background = myBrush;
            RF.Children.Add(myStackPanel);
            XpsDocument doc = new XpsDocument($@"{System.IO.Directory.GetCurrentDirectory()
                        }\Projet04_Equipe02_kacet_daoudi_Manuel d'utilisation_2018.Xps", FileAccess.Read);

            docview.Document = doc.GetFixedDocumentSequence();
        }
コード例 #14
0
        public welcome_acceil()
        {
            InitializeComponent();
            string                  connectString = $@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename={ System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\ProjetBDD.mdf;Integrated Security=True;Connect Timeout=30";
            bool                    full          = false;
            info_entreprise         informa;
            DataClasses1DataContext db = new DataClasses1DataContext(connectString);
            //============================= Animatio ======================================//
            StackPanel myStackPanel = new StackPanel();

            myStackPanel.Height = ActualHeight;
            DoubleAnimation myDoubleAnimation = new DoubleAnimation();

            myDoubleAnimation.From        = 700;
            myDoubleAnimation.To          = 0;
            myDoubleAnimation.Duration    = new Duration(TimeSpan.FromSeconds(5));
            myDoubleAnimation.AutoReverse = false;
            myStackPanel.BeginAnimation(StackPanel.HeightProperty, myDoubleAnimation);
            SolidColorBrush myBrush = new SolidColorBrush();

            myBrush.Color = Colors.White;
            //===============================================================================//


            //=================== Recuparation des informations ==========================//

            info_entreprise info = (from recup in db.info_entreprise select recup).FirstOrDefault();

            if (info != null)
            {
                byte[] array = (byte[])info.Logo.ToArray();

                File.WriteAllBytes($@"{System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\logo.png", array);
                File.WriteAllBytes($@"{System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\\modeles\logo.png", array);
                logo.Source = new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "logo.png", UriKind.Absolute));
            }
            myStackPanel.Background = myBrush;


            g.Children.Add(myStackPanel);



            this.Content = g;

            int i = 0;

            //========================= Bouton de notification ==================================//
            IQueryable <Recrutement> list = from recup in db.Recrutement
                                            select recup;

            foreach (Recrutement rec in list)
            {
                if (rec.date_ent_ != null)
                {
                    i++;
                }
            }
            badgedentretien.Badge = i;
            IQueryable <objectif> list2 = from recup in db.objectif where  recup.fin < DateTime.Today
                                          select recup;

            badgeobjectif.Badge = list2.Count();


            //======================== Raison sociale ================================//

            raison.Text = info.Raison_so;
        }
コード例 #15
0
        private void CreateNavMenuItem(NavMenuItemData item, Panel toAdd, int offset = 0)
        {
            #region создание самого элемента


            DockPanel dock = new DockPanel()
            {
                Height     = ItemHeight,
                Background = new SolidColorBrush(item.IsSelected ? SelectedItemBackground : Background)
            };

            Image icon = null;
            try
            {
                icon = new Image()
                {
                    Height = IconSize,
                    Width  = IconSize,
                    Margin = new Thickness((DropdownIconSectionWidth - IconSize) / 2 + offset, (ItemHeight - IconSize) / 2, (DropdownIconSectionWidth - IconSize) / 2, (ItemHeight - IconSize) / 2),
                    Source = new BitmapImage(item.ImageSource)
                };
                DockPanel.SetDock(icon, Dock.Left);
                dock.Children.Add(icon);
            }
            catch { }


            TextBlock text = new TextBlock()
            {
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left,
                Text       = item.Text,
                Foreground = item.IsSelected ? new SolidColorBrush(SelectedItemTextColor) : new SolidColorBrush(ItemTextColor),
                FontFamily = ItemTextFontFamily,
                FontSize   = ItemTextFontSize,
                FontWeight = ItemTextFontWeight,
                Margin     = new Thickness(0, 0, (ItemHeight - ItemTextFontSize) / 2, 0)
            };
            DockPanel.SetDock(text, Dock.Left);
            dock.Children.Add(text);



            ColorAnimation mouseEnterAnimation = new ColorAnimation()
            {
                From     = item.IsSelected ? SelectedItemBackground : Background,
                To       = MouseInItemBackground,
                Duration = MouseInOverAnimationDuration
            };
            ColorAnimation mouseEnterTextAnimation = new ColorAnimation()
            {
                From     = item.IsSelected ? SelectedItemTextColor : ItemTextColor,
                To       = MouseInItemTextColor,
                Duration = MouseInOverAnimationDuration
            };
            dock.MouseEnter += (object sender, MouseEventArgs e) =>
            {
                if (!this.IsEnabled)
                {
                    return;
                }

                dock.Background.BeginAnimation(SolidColorBrush.ColorProperty, mouseEnterAnimation);
                text.Foreground.BeginAnimation(SolidColorBrush.ColorProperty, mouseEnterTextAnimation);
            };

            ColorAnimation mouseLeaveAnimation = new ColorAnimation()
            {
                From     = MouseInItemBackground,
                To       = item.IsSelected ? SelectedItemBackground : Background,
                Duration = MouseInOverAnimationDuration
            };
            ColorAnimation mouseLeaveTextAnimation = new ColorAnimation()
            {
                To       = item.IsSelected ? SelectedItemTextColor : ItemTextColor,
                From     = MouseInItemTextColor,
                Duration = MouseInOverAnimationDuration
            };
            dock.MouseLeave += (object sender, MouseEventArgs e) =>
            {
                if (!this.IsEnabled)
                {
                    return;
                }

                dock.Background.BeginAnimation(SolidColorBrush.ColorProperty, mouseLeaveAnimation);
                text.Foreground.BeginAnimation(SolidColorBrush.ColorProperty, mouseLeaveTextAnimation);
            };

            MouseClickManager clickManager = new MouseClickManager(200, () => { return(this.IsEnabled); });
            dock.MouseLeftButtonDown += clickManager.OnMouseLeftButtonDown;
            dock.MouseLeftButtonUp   += clickManager.OnMouseLeftButtonUp;

            //обработчик кликов во вне
            clickManager.Click += (object sender, MouseButtonEventArgs e) => { RaiseClickedEvent(item); };

            item.PropertyChanged += (object sender, System.ComponentModel.PropertyChangedEventArgs e) =>
            {
                _context?.Post((s) =>
                {
                    if (sender is NavMenuItemData data)
                    {
                        if (e.PropertyName == "ImageSource")
                        {
                            if (icon != null)
                            {
                                icon.Source = new BitmapImage(data.ImageSource);
                            }
                        }

                        if (e.PropertyName == "Text")
                        {
                            if (text != null)
                            {
                                text.Text = data.Text;
                            }
                        }

                        if (e.PropertyName == "IsSelected")
                        {
                            if (text != null)
                            {
                                text.Foreground = data.IsSelected ? new SolidColorBrush(SelectedItemTextColor) : new SolidColorBrush(ItemTextColor);
                            }

                            if (dock != null)
                            {
                                dock.Background = new SolidColorBrush(data.IsSelected ? SelectedItemBackground : Background);
                            }

                            if (mouseEnterAnimation != null)
                            {
                                mouseEnterAnimation.From = data.IsSelected ? SelectedItemBackground : Background;
                            }

                            if (mouseEnterTextAnimation != null)
                            {
                                mouseEnterTextAnimation.From = data.IsSelected ? SelectedItemTextColor : ItemTextColor;
                            }

                            if (mouseLeaveAnimation != null)
                            {
                                mouseLeaveAnimation.To = data.IsSelected ? SelectedItemBackground : Background;
                            }

                            if (mouseLeaveTextAnimation != null)
                            {
                                mouseLeaveTextAnimation.To = data.IsSelected ? SelectedItemTextColor : ItemTextColor;
                            }
                        }
                    }
                }, null);
            };


            toAdd.Children.Add(dock);

            #endregion

            #region создание подменю

            bool isAnimatedNow = false;
            if (item.IsDropdownItem && item.DropdownItems != null)
            {
                Image dropdownIcon;
                try
                {
                    dropdownIcon = new Image()
                    {
                        Height = DropdownIconSize,
                        Width  = DropdownIconSize,
                        Margin =
                            new Thickness((ItemHeight - DropdownIconSize) / 2.0 > DropdownIconMinLeftOffset ? (ItemHeight - DropdownIconSize) / 2.0 : DropdownIconMinLeftOffset,
                                          (ItemHeight - DropdownIconSize) / 2,
                                          (ItemHeight - DropdownIconSize) / 2,
                                          (ItemHeight - DropdownIconSize) / 2),

                        HorizontalAlignment = HorizontalAlignment.Right,
                        Source          = new BitmapImage(DropdownIconSource),
                        RenderTransform = new RotateTransform(0, DropdownIconSize / 2, DropdownIconSize / 2),
                        Name            = "dropdownIcon"
                    };
                    DockPanel.SetDock(dropdownIcon, Dock.Right);
                    dock.Children.Add(dropdownIcon);
                }
                catch { }


                DoubleAnimation rotateAnimation = new DoubleAnimation()
                {
                    Duration       = DropdownMenuAnimationDuration,
                    EasingFunction = DropdownMenuFunction,
                };

                StackPanel dropdownMenu = new StackPanel()
                {
                    Orientation = Orientation.Vertical,
                    MaxHeight   = 0
                };



                foreach (var el in item.DropdownItems)
                {
                    CreateNavMenuItem(el, dropdownMenu, offset + DropdownMenuLeftOffset);
                }


                DoubleAnimation dropupAnimation = new DoubleAnimation()
                {
                    Duration       = DropdownMenuAnimationDuration,
                    EasingFunction = DropdownMenuFunction
                };

                DoubleAnimationUsingKeyFrames dropdownAnimation = new DoubleAnimationUsingKeyFrames();
                dropdownAnimation.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0)), Value = 0, EasingFunction = DropdownMenuFunction
                });
                dropdownAnimation.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(DropdownMenuAnimationDuration.Milliseconds - 1)), EasingFunction = DropdownMenuFunction
                });
                dropdownAnimation.KeyFrames.Add(new EasingDoubleKeyFrame()
                {
                    KeyTime = KeyTime.FromTimeSpan(DropdownMenuAnimationDuration), Value = 100000
                });

                this.IsEnabledChanged += (object sender, DependencyPropertyChangedEventArgs e) =>
                {
                    if (!(bool)e.NewValue && dropdownMenu.MaxHeight > 0)
                    {
                        dropupAnimation.From = dropdownMenu.RenderSize.Height;
                        dropupAnimation.To   = 0;
                        dropdownMenu.BeginAnimation(Panel.MaxHeightProperty, dropupAnimation);
                    }
                };


                #region обработчик кликов для скрытия/раскрытия меню

                rotateAnimation.Completed += (object sender, EventArgs e) => { isAnimatedNow = false; };

                clickManager.Click += (object sender, MouseButtonEventArgs e) =>
                {
                    if (!isAnimatedNow && (sender is Panel senderPanel))
                    {
                        if (senderPanel.Parent is Panel parentPanel)
                        {
                            var submenu = parentPanel.Children[parentPanel.Children.IndexOf(senderPanel) + 1];

                            if (submenu is Panel submenuPanel)
                            {
                                isAnimatedNow = true;
                                if (submenuPanel.MaxHeight <= 0.1)
                                {
                                    rotateAnimation.From = 0;
                                    rotateAnimation.To   = 180;
                                    dropdownAnimation.KeyFrames[1].Value = submenuPanel.RenderSize.Height;
                                    submenuPanel.BeginAnimation(Panel.MaxHeightProperty, dropdownAnimation);
                                }
                                else
                                {
                                    rotateAnimation.From = 180;
                                    rotateAnimation.To   = 360;
                                    dropupAnimation.From = submenuPanel.RenderSize.Height;
                                    dropupAnimation.To   = 0;
                                    submenuPanel.BeginAnimation(Panel.MaxHeightProperty, dropupAnimation);
                                }


                                if ((LogicalTreeHelper.FindLogicalNode(senderPanel, "dropdownIcon") is Image img) && (img.RenderTransform is RotateTransform transform))
                                {
                                    transform.BeginAnimation(RotateTransform.AngleProperty, rotateAnimation);
                                }
                            }
                        }
                    }
                };
                #endregion

                toAdd.Children.Add(dropdownMenu);
            }

            #endregion
        }
コード例 #16
0
        /// <summary>
        /// 用于执行单个动画的通用函数
        /// </summary>
        /// <typeparam name="TYPE">主体类型</typeparam>
        /// <param name="TarObj">主体引用</param>
        /// <param name="dp">用于动画的依赖项属性</param>
        /// <param name="secTS">时间长度,以秒为单位</param>
        /// <param name="To">目标值</param>
        /// <param name="From">初始值</param>
        /// <param name="fl">完成后的动作</param>
        /// <returns></returns>
        public static int UniversalBeginDoubleAnimation <TYPE>(ref TYPE TarObj, DependencyProperty dp, double secTS, double To, double From = 0F, FillBehavior fl = FillBehavior.HoldEnd)
        {
            if (TarObj == null)
            {
                return(-1);
            }

            DoubleAnimation da = new DoubleAnimation();

            if (From != 0)
            {
                da.From = From;
            }
            da.To           = To;
            da.Duration     = TimeSpan.FromSeconds(secTS);
            da.FillBehavior = fl;
            da.AutoReverse  = false;

            if (typeof(TYPE) == typeof(Window))
            {
                Window wnd = TarObj as Window;
                if (wnd == null)
                {
                    return(-2);
                }
                wnd.BeginAnimation(dp, da);
                return(0);
            }
            else if (typeof(TYPE) == typeof(StackPanel))
            {
                StackPanel stackpanel = TarObj as StackPanel;
                if (stackpanel == null)
                {
                    return(-2);
                }
                stackpanel.BeginAnimation(dp, da);
                return(0);
            }
            else if (typeof(TYPE) == typeof(Border))
            {
                Border border = TarObj as Border;
                if (border == null)
                {
                    return(-2);
                }
                border.BeginAnimation(dp, da);
                return(0);
            }
            else if (typeof(TYPE) == typeof(Button))
            {
                Button button = TarObj as Button;
                if (button == null)
                {
                    return(-2);
                }
                button.BeginAnimation(dp, da);
                return(0);
            }
            else
            {
                return(-3);
            }
        }
コード例 #17
0
        private void AddSection(object sender, RoutedEventArgs e)
        {
            Input sectionInput = new Input();

            sectionInput.AddButton.Content = "Add Section";
            sectionInput.Content.Text      = "Section Name";
            sectionInput.Title             = "New Section";
            sectionInput.ShowDialog();
            if (sectionInput.OK)
            {
                Button sectionElementAdditionButton = new Button
                {
                    Height     = 167,
                    Width      = 167,
                    Margin     = new Thickness(10),
                    Foreground = SystemColors.ControlDarkDarkBrush,
                    Style      = FindResource("MaterialDesignFlatButton") as Style,
                    Content    = new PackIcon
                    {
                        Kind = PackIconKind.PlusBox,
                        HorizontalAlignment = HorizontalAlignment.Center,
                        VerticalAlignment   = VerticalAlignment.Center,
                        Width  = 75,
                        Height = 75
                    }
                };
                Label sectionHeaderLabel = new Label
                {
                    Content             = sectionInput.Content.Text,
                    VerticalAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    FontSize            = 15,
                    FontWeight          = FontWeights.Light,
                    FontFamily          = new FontFamily("Nexa Light")
                };
                Button sectionExpansionButton = new Button
                {
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Style           = FindResource("MaterialDesignFlatButton") as Style,
                    BorderThickness = new Thickness(0),
                    Padding         = new Thickness(0),
                    Height          = 20,
                    Width           = 20,
                    Content         = new PackIcon
                    {
                        HorizontalAlignment = HorizontalAlignment.Center,
                        VerticalAlignment   = VerticalAlignment.Center,
                        Kind = PackIconKind.ChevronDown
                    }
                };
                Button sectionDeletionButton = new Button
                {
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Style   = FindResource("MaterialDesignFlatButton") as Style,
                    Padding = new Thickness(0),
                    Height  = 20,
                    Width   = 20,
                    Content = new PackIcon
                    {
                        HorizontalAlignment = HorizontalAlignment.Center,
                        VerticalAlignment   = VerticalAlignment.Center,
                        Kind = PackIconKind.Close
                    }
                };
                MenuItem sectionExpansionMenuItem = new MenuItem {
                    Header = "Collapse Section"
                };
                MenuItem sectionDeletionMenuItem = new MenuItem {
                    Header = "Delete Section"
                };
                StackPanel sectionSeparator = new StackPanel
                {
                    Background          = Brushes.Transparent,
                    Margin              = new Thickness(5, 15, 5, 5),
                    Orientation         = Orientation.Horizontal,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    ContextMenu         = new ContextMenu
                    {
                        Items =
                        {
                            sectionExpansionMenuItem,
                            sectionDeletionMenuItem
                        }
                    },
                    Children =
                    {
                        sectionExpansionButton,
                        sectionHeaderLabel,
                        sectionDeletionButton
                    }
                };
                WrapPanel sectionElementContainer = new WrapPanel()
                {
                    Orientation   = Orientation.Horizontal,
                    FlowDirection = FlowDirection.LeftToRight
                };
                double sectionElementContainerRecordedHeight = 0;
                sectionElementContainer.Children.Add(sectionElementAdditionButton);
                list.Children.Add(sectionSeparator);
                ThicknessAnimation sectionMarginOpeningAnimation = new ThicknessAnimation
                {
                    Duration       = TimeSpan.FromSeconds(1),
                    From           = new Thickness(-Width, 15, 0, 0),
                    EasingFunction = new CircleEase()
                    {
                        EasingMode = EasingMode.EaseOut
                    },
                    FillBehavior = FillBehavior.Stop
                };
                sectionSeparator.BeginAnimation(MarginProperty, sectionMarginOpeningAnimation);
                list.Children.Add(sectionElementContainer);
                sectionElementContainer.BeginAnimation(MarginProperty, sectionMarginOpeningAnimation);
                sectionElementAdditionButton.Click += (sI, eI) =>
                {
                    Input elementInput = new Input();
                    elementInput.AddButton.Content = "Add to Section";
                    elementInput.Content.Text      = "Element Content";
                    elementInput.Title             = "New Element in Section \"" + sectionInput.Content.Text + "\"";
                    elementInput.ShowDialog();
                    if (elementInput.OK)
                    {
                        Grid     elementContentGrid = new Grid();
                        PackIcon elementPackIcon    = new PackIcon
                        {
                            Kind = PackIconKind.ImageArea,
                            VerticalAlignment   = VerticalAlignment.Center,
                            HorizontalAlignment = HorizontalAlignment.Center,
                            Width      = 75,
                            Height     = 75,
                            Foreground = SystemColors.ControlDarkDarkBrush
                        };
                        CheckBox elementCheckBox = new CheckBox()
                        {
                            HorizontalAlignment = HorizontalAlignment.Left,
                            VerticalAlignment   = VerticalAlignment.Top,
                            Margin = new Thickness(5)
                        };
                        Card element = new Card
                        {
                            Height              = 175,
                            Width               = 175,
                            Margin              = new Thickness(5),
                            Content             = elementContentGrid,
                            HorizontalAlignment = HorizontalAlignment.Left
                        };
                        TextBlock elementTextBlock = new TextBlock
                        {
                            Text              = elementInput.Content.Text,
                            FontFamily        = new FontFamily("Nexa"),
                            VerticalAlignment = VerticalAlignment.Bottom,
                            Margin            = new Thickness(5, 5, 5, 3),
                            Foreground        = SystemColors.ControlDarkBrush
                        };
                        elementContentGrid.Children.Add(elementTextBlock);
                        elementContentGrid.Children.Add(elementCheckBox);
                        elementContentGrid.Children.Add(elementPackIcon);
                        sectionElementContainer.Children.Insert(sectionElementContainer.Children.IndexOf(sectionElementAdditionButton), element);
                        element.BeginAnimation(WidthProperty, new DoubleAnimation
                        {
                            Duration       = TimeSpan.FromSeconds(.2),
                            From           = 0,
                            To             = element.Width,
                            EasingFunction = new CircleEase()
                            {
                                EasingMode = EasingMode.EaseOut
                            },
                            FillBehavior = FillBehavior.Stop
                        });
                        elementCheckBox.Checked += (sII, eII) =>
                        {
                            element.Background          = FindResource("PrimaryHueMidBrush") as Brush;
                            elementCheckBox.Background  = FindResource("MaterialDesignPaper") as Brush;
                            elementPackIcon.Foreground  = FindResource("MaterialDesignPaper") as Brush;
                            elementTextBlock.Foreground = FindResource("MaterialDesignPaper") as Brush;
                        };
                        elementCheckBox.Unchecked += (sII, eII) =>
                        {
                            element.Background          = FindResource("MaterialDesignBackground") as Brush;
                            elementCheckBox.Background  = SystemColors.ControlDarkDarkBrush;
                            elementPackIcon.Foreground  = SystemColors.ControlDarkDarkBrush;
                            elementTextBlock.Foreground = SystemColors.ControlDarkBrush;
                        };
                    }
                };
                bool test2 = false;
                sectionExpansionButton.Click   += ToggleExpansion;
                sectionExpansionMenuItem.Click += ToggleExpansion;
                void ToggleExpansion(object sI, RoutedEventArgs eI)
                {
                    // TODO: Make deletion reset scrollbar and new item placing position
                    DoubleAnimation sectionElementContainerHeightAnimation = new DoubleAnimation
                    {
                        Duration       = TimeSpan.FromSeconds(1),
                        From           = sectionElementContainer.ActualHeight,
                        To             = test2 == false ? 0 : sectionElementContainerRecordedHeight,
                        EasingFunction = new CircleEase()
                        {
                            EasingMode = EasingMode.EaseOut
                        }
                    };

                    sectionElementContainerHeightAnimation.Completed += (sII, eII) =>
                    {
                        if (sectionElementContainer.ActualHeight >= sectionElementAdditionButton.ActualHeight)
                        {
                            sectionElementContainer.BeginAnimation(HeightProperty, null);
                            sectionElementContainer.Height = double.NaN;
                        }
                    };
                    if (sectionElementContainer.ActualHeight >= sectionElementAdditionButton.ActualHeight)
                    {
                        sectionElementContainerRecordedHeight = sectionElementContainer.ActualHeight;
                    }
                    sectionElementContainer.BeginAnimation(HeightProperty, sectionElementContainerHeightAnimation, HandoffBehavior.SnapshotAndReplace);
                    (sectionExpansionButton.Content as PackIcon).Kind = (sectionExpansionButton.Content as PackIcon).Kind == PackIconKind.ChevronDown ? PackIconKind.ChevronUp : PackIconKind.ChevronDown;
                    test2 = !test2;
                };
                sectionDeletionButton.Click   += DeleteSection;
                sectionDeletionMenuItem.Click += DeleteSection;
                void DeleteSection(object sI, RoutedEventArgs eI)
                {
                    ThicknessAnimation sectionMarginClosingAnimation = new ThicknessAnimation
                    {
                        Duration       = TimeSpan.FromSeconds(1),
                        To             = new Thickness(-Width, 15, Width, 0),
                        EasingFunction = new CircleEase()
                        {
                            EasingMode = EasingMode.EaseIn
                        },
                        FillBehavior = FillBehavior.Stop
                    };

                    sectionMarginClosingAnimation.Completed += (sII, eII) =>
                    {
                        list.Children.Remove(sectionSeparator);
                        list.Children.Remove(sectionElementContainer);
                        Console.WriteLine("The animation clock has ended.");
                        Console.WriteLine(list.Children.IndexOf(sectionSeparator));
                        Console.WriteLine(list.Children.IndexOf(sectionElementContainer));
                    };
                    sectionSeparator.BeginAnimation(MarginProperty, sectionMarginClosingAnimation);
                    sectionElementContainer.BeginAnimation(MarginProperty, sectionMarginClosingAnimation);
                };
                sectionElementContainer.SizeChanged += (sI, eI) =>
                {
                    Console.WriteLine(sectionElementContainer.RenderSize);
                };
                sectionElementAdditionButton.MouseEnter += (sI, eI) => Cursor = Cursors.Hand;
                sectionElementAdditionButton.MouseLeave += (sI, eI) => Cursor = Cursors.Arrow;
            }
        }
コード例 #18
0
        private void option1_click(object sender, RoutedEventArgs e)
        {
            StackPanel sp       = sender as StackPanel;
            StackPanel usedToBe = currentlyExpanded;

            if (currentlyExpanded != null)
            {
                double initialHeight = usedToBe.DesiredSize.Height;

                StackPanel sub = new StackPanel();

                shrink();
                this.UpdateLayout();
                double finalHeight = views[usedToBe].stub.DesiredSize.Height;
                sub.Height = initialHeight - finalHeight;
                usedToBe.Children.Add(sub);
                //views[sp].stub.Height = initialHeight;
                this.UpdateLayout();

                Duration            duration        = new Duration(TimeSpan.FromSeconds(0.50));
                DoubleAnimationPlus doubleanimation = new DoubleAnimationPlus();
                doubleanimation.Duration = duration;
                doubleanimation.To       = 0;

                doubleanimation.TargetElement = usedToBe;


                doubleanimation.Completed += new EventHandler(ShrinkAnimationCompleted);

                //views[sp].stub.BeginAnimation(HeightProperty, doubleanimation);
                sub.BeginAnimation(HeightProperty, doubleanimation);
            }
            if (usedToBe != sp)
            {
                double initialHeight = sp.DesiredSize.Height;

                expand(sp);
                this.UpdateLayout();
                double finalHeight = views[sp].DesiredSize.Height;
                //shrink();
                views[sp].Height = initialHeight;
                this.UpdateLayout();



                //StackPanel sub = new StackPanel();
                //sp.Children.Add(sub);

                //sub.Height = 0;


                Duration            duration        = new Duration(TimeSpan.FromSeconds(0.50));
                DoubleAnimationPlus doubleanimation = new DoubleAnimationPlus();
                doubleanimation.Duration = duration;
                //doubleanimation.To = finalHeight - initialHeight;
                doubleanimation.To   = finalHeight;
                doubleanimation.From = initialHeight;

                doubleanimation.TargetElement = sp;

                doubleanimation.Completed += new EventHandler(AnimationCompleted);

                //sub.BeginAnimation(HeightProperty, doubleanimation);
                views[sp].BeginAnimation(HeightProperty, doubleanimation);
            }
        }
コード例 #19
0
ファイル: MainWindow.xaml.cs プロジェクト: skyisbule/danmu
        public void SetBarrage(string content, int img)
        {
            Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() =>
            {
                Dictionary <object, double> ldi = new Dictionary <object, double>();

                int lines = (Convert.ToInt32(this.Height) - 10) / 40;
                int line  = 0;

                Random rd = new Random();

                for (int i = 0; i < lines; i++)
                {
                    ldi.Add(i, 0);
                }

                foreach (StackPanel item in canvas.Children)
                {
                    if (ldi.ContainsKey(item.Tag))
                    {
                        if (ldi[item.Tag] < Convert.ToDouble(item.GetValue(Canvas.LeftProperty)))
                        {
                            ldi[item.Tag] = Convert.ToDouble(item.GetValue(Canvas.LeftProperty));
                        }
                    }
                    else
                    {
                        ldi.Add(item.Tag, Convert.ToDouble(item.GetValue(Canvas.LeftProperty)));
                    }
                }

                if (ldi.Count(m => m.Value == 0) > 1)
                {
                    var list = ldi.Where(m => m.Value == 0).ToList();

                    line = Convert.ToInt32(list[rd.Next(0, list.Count)].Key);
                }
                else
                {
                    line = Convert.ToInt32(ldi.OrderBy(m => m.Value).FirstOrDefault().Key);
                }

                #region StackPanel

                StackPanel sp = new StackPanel();

                sp.Tag         = line;
                sp.Orientation = Orientation.Horizontal;
                sp.SetValue(Canvas.LeftProperty, this.Width);
                sp.SetValue(Canvas.TopProperty, Convert.ToDouble(40 * line) + 10);

                TextBlock tb = new TextBlock();

                tb.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                tb.FontSize          = 50;
                tb.Text = content;

                tb.Foreground = new SolidColorBrush(Color.FromRgb(
                                                        Convert.ToByte(rd.Next(0, 255)),
                                                        Convert.ToByte(rd.Next(0, 255)),
                                                        Convert.ToByte(rd.Next(0, 255))));

                sp.Children.Add(tb);

                /*
                 * GifImage gi = new GifImage();
                 *
                 * gi.Width = 24;
                 * gi.Height = 24;
                 * gi.Source = "images/e" + (img + 100) + ".gif";
                 *
                 * sp.Children.Add(gi);
                 */


                canvas.Children.Add(sp);


                DoubleAnimation animation =
                    new DoubleAnimation(this.Width, -this.Width, new Duration(TimeSpan.FromSeconds(33)));

                animation.Completed += new EventHandler((object o, EventArgs arg) =>
                {
                    canvas.Children.Remove(sp);
                });

                sp.BeginAnimation(Canvas.LeftProperty, animation);

                #endregion
            }));
        }