ListBox animation and ListBoxItem animation

Написал пример программной анимации для Windows Phone. Многим может пригодится.

private void animatelistboxItem(ListBoxItem item)
        {
            Storyboard sb = null;
            string animationstoryname=item.GetHashCode().ToString() +  "_listBoxItem_story";

            if (LayoutRoot.Resources[animationstoryname] != null)
            {
                sb = (LayoutRoot.Resources[animationstoryname] as Storyboard);
                sb.Stop();
                sb.Begin();
                return;
            }
            else
            {
                sb = new Storyboard();
            }

            if (item.Projection == null)
            {
                item.Projection = new PlaneProjection(); 
            }
            DoubleAnimation danim = createanimation(TimeSpan.FromMilliseconds(0), 1.0, 359.0, 0.0, item.Projection as PlaneProjection);
            sb.Children.Add(danim);
            Storyboard.SetTarget(danim, item.Projection);
            Storyboard.SetTargetProperty(danim, new PropertyPath(PlaneProjection.RotationYProperty));

            sb.Duration = new Duration(TimeSpan.FromSeconds(1));

            if (LayoutRoot.Resources[animationstoryname] == null)
            {
                LayoutRoot.Resources.Add(animationstoryname, sb);
            }
            sb.Begin();

        }
private void animatelistbox(ListBox  listBox) {

            Storyboard sb=null ;
            string animationstoryname = listBox.GetHashCode().ToString() + "_listBox_story";

            if (LayoutRoot.Resources[animationstoryname] != null)
            {
                sb = (LayoutRoot.Resources[animationstoryname] as Storyboard);
                sb.Stop();
                sb.Begin();
                return;
            }
            else
            {
                sb = new Storyboard();
            }

            int i = 0;

            foreach (ListBoxItem item in listBox.Items)
            {
                if (item.Projection == null)
                {
                    item.Projection = new PlaneProjection(); 
                }

                DoubleAnimation danim = createanimation(TimeSpan.FromMilliseconds(i * 100), 0.5, 90.0, 0.0, item.Projection as PlaneProjection);
                sb.Children.Add(danim);
                Storyboard.SetTarget(danim, item.Projection);
                Storyboard.SetTargetProperty(danim, new PropertyPath(PlaneProjection.RotationXProperty)); 
                i++;
            }
            sb.Duration = new Duration(TimeSpan.FromSeconds(i));

            if (LayoutRoot.Resources[animationstoryname] == null)
            {
                LayoutRoot.Resources.Add(animationstoryname, sb);
            }
            sb.Begin();
        
        }

Добавить комментарий

Loading