예제 #1
0
        /// <summary>
        /// Called when the navigation has completed.
        /// </summary>
        /// <remarks>
        /// This should of course be a cleaner solution, but there is no other way to let a view-model
        /// know that navigation has completed. Another option is injection, but this would require every
        /// view-model for Windows Phone 7 to accept only the navigation context, which has actually nothing
        /// to do with the logic.
        /// <para/>
        /// It is also possible to use the <see cref="NavigationCompleted"/> event.
        /// </remarks>
        protected override void OnNavigationCompleted()
        {
            if (NavigationContext.Values.ContainsKey("ShoppingListIndex"))
            {
                int.TryParse((string)NavigationContext.Values["ShoppingListIndex"], out _shoppingListIndex);
            }

            if (_shoppingListIndex == -1)
            {
                ShoppingList = new Data.ShoppingList();
                UserData.Instance.ShoppingLists.Add(ShoppingList);
                _shoppingListIndex = UserData.Instance.ShoppingLists.IndexOf(ShoppingList);
            }
            else
            {
                ShoppingList = UserData.Instance.ShoppingLists[_shoppingListIndex];
            }
        }
        /// <summary>
        /// Called when the navigation has completed.
        /// </summary>
        /// <remarks>
        /// This should of course be a cleaner solution, but there is no other way to let a view-model
        /// know that navigation has completed. Another option is injection, but this would require every
        /// view-model for Windows Phone 7 to accept only the navigation context, which has actually nothing
        /// to do with the logic.
        /// <para/>
        /// It is also possible to use the <see cref="NavigationCompleted"/> event.
        /// </remarks>
        protected override void OnNavigationCompleted()
        {
            if (NavigationContext.Values.ContainsKey("ShoppingListIndex"))
            {
                int.TryParse((string)NavigationContext.Values["ShoppingListIndex"], out _shoppingListIndex);
            }

            if (_shoppingListIndex == -1)
            {
                ShoppingList = new Data.ShoppingList();
                UserData.Instance.ShoppingLists.Add(ShoppingList);
                _shoppingListIndex = UserData.Instance.ShoppingLists.IndexOf(ShoppingList);
            }
            else
            {
                ShoppingList = UserData.Instance.ShoppingLists[_shoppingListIndex];
            }
        }