Esempio n. 1
0
        /// <summary>
        /// Update the favorite list, attaching all required event handlers.
        /// We will load favorites from isolated storage, on the state of the
        /// input parameter
        /// </summary>
        /// <param name="favoritesListView">List view for the favorites</param>
        /// <param name="favoritesNoItems">Text block for the favorites</param>
        internal void UpdateFavoriteList(
            ListBox favoritesListView,
            TextBlock favoritesNoItems)
        {
            FavoriteCollection favCollection = ApplicationState.Favorites == null ?
                                               favCollection = FavoriteCollection.LoadFromFile() : ApplicationState.Favorites;

            if (favCollection.Count > 0)
            {
                // show listbox, hide no favorites label
                favoritesListView.Visibility  = Visibility.Visible;
                favoritesNoItems.Visibility   = Visibility.Collapsed;
                favoritesListView.ItemsSource = favCollection;
            }
            else
            {
                // hide listbox, show no favorites label
                favoritesListView.Visibility = Visibility.Collapsed;
                favoritesNoItems.Visibility  = Visibility.Visible;
            }

            // We need to instal these handlers in the order below to be sure they don't get
            // eaten by the ListView control
            this.lastSelectedFavorite = null;
        }
        /// <summary>
        /// Background thread work for loading
        /// The loading of the supported conversions from the Xap as well as the
        /// favorites from isolated storage is done on a non UI thread to allow the
        /// fastest possible page render
        /// </summary>
        /// <param name="sender">worker thread object</param>
        /// <param name="e">Action delegate for completion</param>
        private void DeferStartupWork(object sender, DoWorkEventArgs e)
        {
            Action completed = e.Argument as Action;

            lock (threadLock)
            {
                ApplicationState.AppLaunchInitialization();

                this.SetDefaultCategoryAndUnits();
                ApplicationState.Favorites =
                    FavoriteCollection.LoadFromFile() ?? new FavoriteCollection();
            }

            if (completed != null)
            {
                completed();
            }
        }