Exemple #1
0
 /// <summary>
 /// Setup the shopping cart feature
 /// </summary>
 public static void Create(CustomPivotViewer pivotViewer)
 {
     // Don't need to save a reference to the object created here, because the
     // ShoppingCart will be referenced by the PivotViewer to which it is
     // attached
     new ShoppingCart(pivotViewer);
 }
Exemple #2
0
        /// <summary>
        /// Construct an instance of ShoppingCart
        /// </summary>
        private ShoppingCart(CustomPivotViewer pivotViewer)
        {
            if (pivotViewer.GetCustomActionsForItemCallback != null)
            {
                throw new InvalidOperationException(
                          "Shopping cart must be the only handler for a CustomPivotViewer's GetCustomActionsForItemCallback");
            }

            // Redirect calls to our PivotViewer's GetCustomActionsForItem to our own method
            pivotViewer.GetCustomActionsForItemCallback = this.GetCustomActionsForItem;

            m_pivotViewer = pivotViewer;

            // Hook the ItemActionExecuted event handler
            m_pivotViewer.ItemActionExecuted += PivotViewer_ItemActionExecuted;

            // Check for the CartContentsGrid element, and if it exists make it visible. Doing this
            // dynamically allows the application to build & run if the element is removed
            FrameworkElement cartContentsGrid = m_pivotViewer.FindName("CartContentsGrid") as FrameworkElement;

            if (cartContentsGrid != null)
            {
                cartContentsGrid.Visibility = Visibility.Visible;
            }

            // Build the "Add to Cart" custom action
            s_addCustomAction =
                new CustomAction(
                    "Add to Cart",
                    GetIconUri("Add.png"),
                    "Adds the item to the cart",
                    AddItemActionId);

            // Build the "Remove from Cart" custom action
            s_removeCustomAction =
                new CustomAction(
                    "Remove from Cart",
                    GetIconUri("Remove.png"),
                    "Removes the item from the cart",
                    RemoveItemActionId);
        }