/// <summary>
        ///  Adds a new collapsed product item to the top of products list.
        /// </summary>
        /// <param name="barcode"></param>
        public void AddProduct(string barcode, WriteableBitmap bitmap)
        {
            if (RootGrid.Children.Count > MaxCount)
                return;

            if (ContainsProduct(barcode))
            {
                MoveProductItemToTop(GetProductItem(barcode));
                return;
            }

            ProductItem productItem = new ProductItem(barcode, bitmap);
            productItem.VerticalAlignment = VerticalAlignment.Bottom;
            productItem.Tapped += (sender, e) =>
                {
                    if (productItem.Product == null)
                        return;
                    OnProductSelected(productItem);
                };

            double y = -RootGrid.Children.Count * (ProductItem.DefaultHeight + ProductItem.Space);
            ((CompositeTransform)productItem.RenderTransform).TranslateY = y;
            RootGrid.Children.Add(productItem);

            if (RootGrid.Children.Count > MaxCount)
            {
                ProductItem itemToRemove = (ProductItem)RootGrid.Children.First();
                itemToRemove.Hidden += (sender, e) =>
                    {
                        RootGrid.Children.Remove(itemToRemove);
                        //RootGrid.Children.OrderBy((item) =>
                        //    {
                        //        return ((ProductItem)item).Translation.Y;
                        //    });
                    };
                itemToRemove.Hide();
                foreach (ProductItem item in RootGrid.Children)
                    item.SlideDown();
            }
        }
        public void Open(ProductItem productItem)
        {
            GeneralTransform productItemTransform = this.TransformToVisual(productItem);
            Point productItemPosition = productItemTransform.TransformPoint(new Point(0, ContentGrid.ActualHeight / 2));
            openPosition = -productItemPosition.Y + 19; // Measured offset just better looking animation.
            ((CompositeTransform)ContentGrid.RenderTransform).TranslateY = openPosition;
            FadeInSotryboard.Begin();
            isOpen = true;
            ContentGrid.IsHitTestVisible = isOpen;
            if (productItem.Product != null)
            {
                this.Product = productItem.Product;
                this.Bitmap = productItem.Bitmap;
            }

            PlWorkersCheck.Show(TimeSpan.FromSeconds(0.2));
            PlRndCheck.Show(TimeSpan.FromSeconds(0.3));
            PlRegisteredCheck.Show(TimeSpan.FromSeconds(0.4));
            PlNotGlobalCheck.Show(TimeSpan.FromSeconds(0.5));
        }
 private void OnProductSelected(ProductItem productItem)
 {
     if (ProductSelected != null)
         ProductSelected(productItem, new ProductEventArgs(productItem.Product));
 }
        /// <summary>
        /// Moves product item to the top of the list with nice slide animation.
        /// </summary>
        /// <param name="productItem"></param>
        private void MoveProductItemToTop(ProductItem productItem)
        {
            if (!RootGrid.Children.Contains(productItem))
                return;

            int aboveItemsCount = 0;
            foreach (ProductItem item in RootGrid.Children)
                if (item.Translation.Y < productItem.Translation.Y)
                {
                    aboveItemsCount++;
                    item.SlideDown();
                }
            productItem.SlideUp(aboveItemsCount);
            RootGrid.Children.Move((uint)RootGrid.Children.IndexOf(productItem), (uint)RootGrid.Children.Count - 1);
        }