//public void LoadComponent() {

        //    this.Visibility = System.Windows.Visibility.Visible;
        //    PanaromaPages_Loaded(new object(), new RoutedEventArgs());
         

        //}


        public PanaromaPages(TList chlist, int chlistIndex)
        {

            InitializeComponent();
            this.DataContext = App.View;
            this.panoNewsItem1.Visibility = System.Windows.Visibility.Visible;
            this.Loaded += new RoutedEventHandler(PanaromaPages_Loaded);
            
        }
        void PanaromaPages_Loaded(object sender, RoutedEventArgs e)
        {

            foreach (TList ShopLists in App.View.DBShop.PLists)
            {
                if (ShopLists.Name == panoNewsItem1.Header.ToString())
                    kaynak = ShopLists;
            }
            var query = from TProduct product in App.View.DBShop.Products join TList listr in App.View.DBShop.PLists on product._PListId equals listr.Id where product._PListId == kaynak.Id select product;
            ProductPanoItemsListBox.ItemsSource = query;


        }
        private void appBarOkButton_Click(object sender, EventArgs e)
        {
            if (ListNameTextBox.Text.Length > 0)
            {
                // Create a new shoplist
                TList newListItem = new TList
                {
                    Name = ListNameTextBox.Text,
                   
                };

                // Add the new shoplist to the View.
                App.View.AddList(newListItem);

                // Return to the main page.
                if (NavigationService.CanGoBack)
                {
                    NavigationService.GoBack();
                }

            }
           
        }
        private void button2_Click(object sender, RoutedEventArgs e)
        {
            foreach (TList ShopLists in App.View.DBShop.PLists)
            {
                if (ShopLists.Name == panoNewsItem1.Header.ToString())
                    kaynak = ShopLists;
                itemID = kaynak.Id;
            }

            var frame2 = App.Current.RootVisual as PhoneApplicationFrame;
            frame2.Navigate(new Uri(string.Format("/NewProductPage.xaml?itemID={0}", itemID), UriKind.Relative));
         
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            decimal sum = 0;
            foreach (TList ShopLists in App.View.DBShop.PLists)
            {
                if (ShopLists.Name == panoNewsItem1.Header.ToString())
                    kaynak = ShopLists;
               
            }
            //var kaynak=(TList)panoNewsItem1.Header;
            var query = from TProduct product in App.View.DBShop.Products join TList listr in App.View.DBShop.PLists on product._PListId equals listr.Id where product._PListId == kaynak.Id select product;
            foreach (TProduct proce in query)
            {
                sum += proce.Price;
            }

            MessageBox.Show(string.Format("Your shopping costs:{0}", sum));
        }
        public void DeleteList(TList ListDelete)
        {

            // Remove shop list from the observable collection.
            ProductLists.Remove(ListDelete);

            // Remove shop list from the data context.
            DBShop.PLists.DeleteOnSubmit(ListDelete);

            // Save changes to the database.
            DBShop.SubmitChanges();
        }
        public void AddList(TList newList)
        {
            // Add new shop list to the data context.
            DBShop.PLists.InsertOnSubmit(newList);

            // Save changes to the database.
            DBShop.SubmitChanges();

            // Add new shop list to  observable collection.
            ProductLists.Add(newList);

        }