protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            string _identity = "-1";
            if (NavigationContext.QueryString.TryGetValue("identity", out _identity))
            {
                if (!string.IsNullOrWhiteSpace(_identity))
                {
                    lblTitulo.Text = "Editar";
                    lblIdentity.Text = _identity;
                    using (var context = new MercadoDbContext(App._connectionString))
                    {
                        var query = (from _con in context.Produtos
                                     where _con.Id == int.Parse(_identity)
                                     select _con).FirstOrDefault();

                        txtNome.Text = query.Nome;
                        txtPreco.Text = query.Preco.ToString();
                        txtDescricao.Text = query.Descricao;
                    }
                }
                else
                {
                    lblIdentity.Text = string.Empty;
                    lblTitulo.Text = "Adicionar";
                }
            }
        }
        public void Carregar()
        {
            IList<Produto> _contato = null;

            using (var _context = new MercadoDbContext(App._connectionString))
            {
                IQueryable<Produto> _query = _context.Produtos;
                _contato = _query.ToList();

                this.Itens.Clear();
                foreach (var item in _contato)
                {
                    this.Itens.Add(item);
                }
            }
        }
        private void btnRemover_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Deseja remover o produto?",
                "Atenção", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            {
                using (var context = new MercadoDbContext(App._connectionString))
                {
                    Produto _p = (mainLista.SelectedItem as Produto);

                    context.Produtos.Attach(_p);
                    context.Produtos.DeleteOnSubmit(_p);
                    context.SubmitChanges();

                    _p = null;
                }
                App.ViewProduto.Carregar();
            }
        }
        /// <summary>
        /// Constructor for the Application object.
        /// </summary>
        public App()
        {
            // Global handler for uncaught exceptions.
            UnhandledException += Application_UnhandledException;

            // Standard XAML initialization
            InitializeComponent();

            // Phone-specific initialization
            InitializePhoneApplication();

            // Language display initialization
            InitializeLanguage();

            // Show graphics profiling information while debugging.
            if (Debugger.IsAttached)
            {
                // Display the current frame rate counters.
                Application.Current.Host.Settings.EnableFrameRateCounter = true;

                // Show the areas of the app that are being redrawn in each frame.
                //Application.Current.Host.Settings.EnableRedrawRegions = true;

                // Enable non-production analysis visualization mode,
                // which shows areas of a page that are handed off to GPU with a colored overlay.
                //Application.Current.Host.Settings.EnableCacheVisualization = true;

                // Prevent the screen from turning off while under the debugger by disabling
                // the application's idle detection.
                // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
                // and consume battery power when the user is not using the phone.
                PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
            }

            using (var _context = new MercadoDbContext(App._connectionString))
            {
                if (!_context.DatabaseExists()) _context.CreateDatabase();
            }

        }
        private void Editar()
        {
            using (var _context = new MercadoDbContext(App._connectionString))
            {
                Produto _contato = (_context.Produtos.Where(a => a.Id == int.Parse(lblIdentity.Text)).First() as Produto);

                _contato.Nome = txtNome.Text;
                _contato.Preco = int.Parse(txtPreco.Text);
                _contato.Descricao = txtDescricao.Text;

                try
                {
                    _context.SubmitChanges();

                    if (NavigationService.CanGoBack) NavigationService.GoBack();
                }
                catch (Exception erro)
                {
                    MessageBox.Show(erro.Message);
                }
            }
        }
        private void Inserir()
        {
            using (var _context = new MercadoDbContext(App._connectionString))
            {
                Produto _p = new Produto()
                {
                    Nome = txtNome.Text,
                    Preco = int.Parse(txtPreco.Text),
                    Descricao = txtDescricao.Text
                };

                try
                {
                    _context.Produtos.InsertOnSubmit(_p);
                    _context.SubmitChanges();

                    if (NavigationService.CanGoBack) NavigationService.GoBack();
                }
                catch (Exception erro)
                {
                    MessageBox.Show(erro.Message);
                }
            }
        }