private void Items_CollectionChanged(object sender, EventArgs e)
 {
     if (itemCount != lstBoxMem.Items.Count)
     {
         count++;
         if (count % 2 == 0)
         {
             ListBoxItem firstItem = (ListBoxItem)lstBoxMem.ItemContainerGenerator.ContainerFromIndex(0);
             firstItem.Opacity = 0;
             if (count == 4)
             {
                 DoubleAnimation heightAnimation = new DoubleAnimation();
                 heightAnimation.From      = 0;
                 heightAnimation.To        = firstItem.ActualHeight;
                 heightAnimation.Duration  = TimeSpan.FromSeconds(0);
                 heightAnimation.BeginTime = TimeSpan.FromSeconds(0.3);
                 firstItem.BeginAnimation(HeightProperty, heightAnimation);
                 DoubleAnimation opacityAnimation = new DoubleAnimation();
                 opacityAnimation.From      = 0;
                 opacityAnimation.To        = 1;
                 opacityAnimation.Duration  = TimeSpan.FromSeconds(0.3);
                 opacityAnimation.BeginTime = TimeSpan.FromSeconds(0.3);
                 firstItem.BeginAnimation(OpacityProperty, opacityAnimation);
                 ThicknessAnimation marginAnimation = new ThicknessAnimation();
                 marginAnimation.From      = new Thickness(-5, 0, 5, 0);
                 marginAnimation.To        = new Thickness(-5, 0, 0, 0);
                 marginAnimation.Duration  = TimeSpan.FromSeconds(0.3);
                 marginAnimation.BeginTime = TimeSpan.FromSeconds(0.3);
                 firstItem.BeginAnimation(MarginProperty, marginAnimation);
                 itemCount = lstBoxMem.Items.Count;
                 count     = 0;
             }
         }
     }
 }
        private void AddHistoryItem(ListBoxItem item)
        {
            if (ListBoxHistory.Items.Count > 8)
            {
                ListBoxHistory.Items.RemoveAt(0);
            }

            DoubleAnimation anim = new DoubleAnimation(0, new Duration(TimeSpan.FromSeconds(2)));

            anim.BeginTime = TimeSpan.FromSeconds(Properties.Settings.Default.ConsoleFadeTime);

            item.HorizontalContentAlignment = HorizontalAlignment.Right;
            item.VerticalContentAlignment   = VerticalAlignment.Center;

            ListBoxHistory.Items.Add(item);

            item.BeginAnimation(OpacityProperty, anim);
        }
Beispiel #3
0
        public void OnPrevious()
        {
            if (_view == null || _view.Count <= NewsPerPage)
            {
                return;
            }
            if (_animationStarted)
            {
                return;
            }
            _animationStarted = true;
            ListBoxItem element    = (ListBoxItem)_listSelector.ItemContainerGenerator.ContainerFromItem(_view.FirstOrDefault());
            double      itemheight = 0;

            if (element != null)
            {
                itemheight = element.ActualHeight + element.Margin.Top + element.Margin.Bottom;
                if (itemheight == 0)
                {
                    itemheight = 20;
                }
            }
            else
            {
                return;
            }
            _view.Move(_view.Count - 1, 0);
            //TODO: need to optimize the animation

            ListBoxItem     firstelement    = (ListBoxItem)_listSelector.ItemContainerGenerator.ContainerFromItem(_view.FirstOrDefault());
            DoubleAnimation heightAnimation = new DoubleAnimation(0, itemheight, TimeSpan.FromSeconds(0.5));

            heightAnimation.FillBehavior = FillBehavior.HoldEnd;
            heightAnimation.Completed   += (s, e) =>
            {
                _animationStarted = false;
            };
            firstelement.BeginAnimation(ListBoxItem.HeightProperty, heightAnimation);
            if (_isItemsUpdate)
            {
                _isItemsUpdate = false;
            }
        }
Beispiel #4
0
        public void OnNext()
        {
            if (_view == null || _view.Count <= NewsPerPage)
            {
                return;
            }
            if (_animationStarted)
            {
                return;
            }
            _animationStarted = true;
            ListBoxItem element    = (ListBoxItem)_listSelector.ItemContainerGenerator.ContainerFromItem(_view.FirstOrDefault());
            double      itemheight = 0;

            if (element != null)
            {
                itemheight = element.ActualHeight + element.Margin.Top + element.Margin.Bottom;
                if (itemheight == 0)
                {
                    itemheight = 20;
                }
            }
            else
            {
                return;
            }

            List <object> itemscache = new List <object>(_listSelector.ItemsSource.Cast <object>().ToList());

            _view.Add(itemscache[0]);
            ListBoxItem lastElement = (ListBoxItem)_listSelector.ItemContainerGenerator.ContainerFromItem(itemscache[0]);

            if (lastElement != null)
            {
                lastElement.Visibility = Visibility.Collapsed;
            }
            ListBoxItem     firstElement    = (ListBoxItem)_listSelector.ItemContainerGenerator.ContainerFromItem(_view.FirstOrDefault());
            DoubleAnimation heightAnimation = new DoubleAnimation(itemheight, 0, TimeSpan.FromSeconds(0.5));

            heightAnimation.FillBehavior = FillBehavior.Stop;
            heightAnimation.Completed   += (s, e) =>
            {
                if (_animateTimer != null && _animateTimer.IsEnabled && !_isItemsUpdate)
                {
                    if (AnimationIndex == 9999)
                    {
                        AnimationIndex = 0;
                    }
                    else
                    {
                        AnimationIndex++;
                    }
                    _view.RemoveAt(0);
                }
                _animationStarted = false;
            };
            if (_isItemsUpdate)
            {
                _isItemsUpdate = false;
            }
            firstElement.BeginAnimation(ListBoxItem.HeightProperty, heightAnimation);
            lastElement.Visibility = Visibility.Visible;
        }