Inheritance: System.Windows.Controls.UserControl
        //This function handles MainPage.Loaded event.
        //This event fires, when navigate to MainPage with NavigationService.GoBake()
        //or NavigationService.Navigate(). Such navigation appear when the user navigates
        //from EditItemPage, SettingsPage, SkyDrive etc.
        //The most important navigation is - MainPage <- SettingsPage, because there user select
        //Pivot display mode or Filter list mode.
        //In this case it's necessary to update layout if it is not valid.
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            //To choose what layout to display (Pivot control or Filtered list)
            //at first check application settings and check current layout.
            //If current layout is invalid - change layout with deleting old
            //displaying control and inserting new control for corresponding settings.
            if (LayoutRoot.Children.Count == 1)
            {
                if ((bool)App.Settings.FiltersSettings)
                {
                    //Using Pivot layout for the MainPage
                    Control elem = new CustomFilterListControl();
                    LayoutRoot.Children.Insert(0, elem);
                }
                else
                {
                    //Using Filtered list layout
                    Control elem = new CustomPivotControl();
                    LayoutRoot.Children.Insert(0, elem);
                }
            }
            else if (LayoutRoot.Children.Count == 2)
            {
                Control currentControl = LayoutRoot.Children[0] as Control;
                Type type = currentControl.GetType();

                //Displaying Pivot control
                if ((bool)App.Settings.FiltersSettings && type == typeof(CustomPivotControl))
                {
                    LayoutRoot.Children.RemoveAt(0);
                    Control newControl = new CustomFilterListControl();
                    LayoutRoot.Children.Insert(0, newControl);
                }
                //Displaying Filtered list
                else if (!(bool)App.Settings.FiltersSettings && type == typeof(CustomFilterListControl))
                {
                    LayoutRoot.Children.RemoveAt(0);
                    Control newControl = new CustomPivotControl();
                    LayoutRoot.Children.Insert(0, newControl);
                }
                else
                {
                    //Nothing to do, because MainPage layout is valid
                }
            }
            //If 'LayoutRoot' grid contain more than 2 children, than we have an exception
            //with current layout
            else
            {
                throw new Exception("There is an exception in the page's layout");
            }

            //Close splash screen
            splashScreenPopup.IsOpen = false;
            PopupSplashScreen screen = splashScreenPopup.Child as PopupSplashScreen;
            screen.loadingProgress.IsIndeterminate = false;
        }
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            splashScreenPopup = new Popup();
            splashScreenPopup.Child = new PopupSplashScreen();
            splashScreenPopup.IsOpen = true;

            //Set the MainPage.Loaded handler
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);

            //Checking loading data from database
            if (!App.ViewModel.IsDataLoaded)
            {
                //If data is not loaded from database than - Load
                App.ViewModel.LoadData();
            }
            // Set the data context of the listbox control to the sample data
            DataContext = App.ViewModel;

            //If there is an empty database (first start of application?)?
            if (App.ViewModel.ShoppingLists.Count == 0)
                //Than add new empty list with "my new list" name
                App.ViewModel.AddNewList(new ShoppingList() { ListName = "my new list" });

            //Choosing what layout to display on the MainPage of application - Pivot or Filtered list.
            //For Pivot layout using CustomPivotControl, for Filtered list - CustomFilteredListControl.
            //All this controls have specific layout to display Lists and list items in corresponding way
            //
            //With the start of application 'LaytouRoot' grid has one child
            // - it's a grid, that contain 'Add' button and TaxtBox to input new item's name.
            //Thus, for display the shopping lists from database it's necessary to add the control
            //with corresponding layout.
            if ((bool)App.Settings.FiltersSettings)
            {
                //Using Pivot layout for the MainPage
                Control elem = new CustomFilterListControl();
                LayoutRoot.Children.Insert(0, elem);
            }
            else
            {
                //Using Filtered list layout
                Control elem = new CustomPivotControl();
                LayoutRoot.Children.Insert(0, elem);
            }
        }