internal void OnLeave(object sender, EventArgs ea)
        {
            if (ItemByWidth == 1)
                return;

            ListBoxItem li = sender as ListBoxItem;

            if (li.IsSelected)
                return;

            FrameworkElement fel = VisualTreeHelper.GetChild(li, 0) as FrameworkElement;

            while ((fel != null) && (fel.ContextMenu == null))
            {
                fel = VisualTreeHelper.GetChild(fel, 0) as FrameworkElement;
            }


            if (fel != null)
            {
                if (fel.ContextMenu.IsOpen)
                {
                    fel.ContextMenuClosing += new ContextMenuEventHandler(fel_ContextMenuClosing);
                    return;
                }
            }

            StopCurrentAnimation();
            _EnterSB = Build(li, 0, TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(500));

            _EnterSB.Storyboard.Begin(this, true);
        }
 private void StopCurrentAnimation()
 {
     if (_EnterSB != null)
     {
         _EnterSB.Storyboard.Stop(this);
         _EnterSB.Storyboard.Remove(this);
         _EnterSB.Cancel();
         _EnterSB = null;
     }
 }
        internal void OnEnter(object sender, EventArgs ea)
        {
            if (ItemByWidth == 1)
                return;

            ListBoxItem li = sender as ListBoxItem;

            if (li.IsSelected)
                return;

            StopCurrentAnimation();

            _EnterSB = Build(li, Dist, TimeSpan.FromMilliseconds(150), TimeSpan.FromMilliseconds(300));
  
            _EnterSB.Storyboard.Begin(this,true);
        }
        private StoryBoardControlable Build(ListBoxItem liss, double Distance, TimeSpan dur, TimeSpan ts)
        {
            Storyboard sb = new Storyboard();

            ListBox lb = ListBoxOwner as ListBox;
            int res = lb.ItemContainerGenerator.IndexFromContainer(liss);
            List<Tuple<ListBoxItem, double>> tobe = new List<Tuple<ListBoxItem,double>>();

            for (int i = _StartIndex; i < _StartIndex+InternalChildren.Count; i++)
            {
                ListBoxItem lis = lb.ItemContainerGenerator.ContainerFromIndex(i) as ListBoxItem;
                if (lis == null)
                    continue;

                double target = (i < res) ? Distance : 0;
                
                DoubleAnimation db = new DoubleAnimation();
                db.To = target;
                db.Duration = dur;
                db.BeginTime = FromOriginalAndDistance(ts,dur,res - i);
                db.AccelerationRatio = 0.1;
                db.DecelerationRatio = 0.1;

                tobe.Add(new Tuple<ListBoxItem,double>(lis,target));

                Storyboard.SetTarget(db, lis);
                Storyboard.SetTargetProperty(db, new PropertyPath("RenderTransform.X"));
                sb.Children.Add(db);
            }

            StoryBoardControlable resfinal = new StoryBoardControlable(sb);

            EventHandler handler = null;
            handler = delegate
            {
                resfinal.Storyboard.Completed -= handler;
                resfinal.Storyboard.Remove(this);

                if (!resfinal.IsCancelled)
                {
                    if (object.ReferenceEquals(resfinal,resfinal.Storyboard))
                        _EnterSB = null;

                    tobe.Apply(li => SetTranslateLI(li.Item1, li.Item2));
                }
            };
            sb.Completed += handler;

            return resfinal;
        }