I have a Custom User Control in the page. In this Custom User Control there are labels, DELETE ITEM Button and Quantity Textbox. In my page there is a ListBox which gets items from list, list is generated from local storage.
Now When I click on DELETE ITEM Button, It Goes to ListBox_SelectionChanged and takes the Selectedindex and further goes to DeleteButton_Tap and provides Selectedindex to it and deletes the item.
Now the problem is, if i click inside Quantity Textbox, it does not first goto ListBox_SelectionChanged to get SelectedIndex of item you want to update the quantity. but it directly goes to QuantityBox_TextChanged inside Custom User Control.
How can i send the SelectedIndex of the item of which i am trying to change the quantity?
EDIT-----------------------------CODE of Custom Control//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
namespace XMLParsing
{
public partial class CustomCartFavControl : UserControl
{
public CustomCartFavControl()
{
InitializeComponent();
}
Singleton singletonInstance = Singleton.mft;
private const string strConnectionString = @"isostore:/MFTDB9.sdf";
private void deleteItem_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
//Confirm:
MessageBoxResult resultDelete = MessageBox.Show("Delete This Item From Cart?", "Cart:", MessageBoxButton.OKCancel);
if (resultDelete == MessageBoxResult.OK)
{
using (MFTDataContext MFTdb = new MFTDataContext(strConnectionString))
{
IQueryable<Database> ListQuery = from Item in MFTdb.MFTCart where Item.ProductUniqueID == singletonInstance.CartItemIDs[singletonInstance.ItemToChange] select Item;
Database itemRemove = ListQuery.FirstOrDefault();
MFTdb.MFTCart.DeleteOnSubmit(itemRemove);
MFTdb.SubmitChanges();
}
singletonInstance.somethingDeletedFromCart = true;
}
else if (resultDelete == MessageBoxResult.Cancel)
{
singletonInstance.somethingDeletedFromCart = false;
}
//END
}
private void QuantityBoxLabel_TextChanged_1(object sender, TextChangedEventArgs e)
{
if (QuantityBoxLabel.Text != "")
{
singletonInstance.QuantityChanged = int.Parse(QuantityBoxLabel.Text);
}
}
private void QuantityBoxLabel_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
//Update Cart
if (singletonInstance.QuantityOriginal == singletonInstance.QuantityChanged)
{
//Do Nothing! Quantity Not Changed
singletonInstance.SomethingChanged = false;
}
else
{
//Work here for Quantity Update etc code:
singletonInstance.SomethingChanged = true;
//((Cart)this.Page).UpdateCartMethod();
if (singletonInstance.QuantityChanged == 0)
{
// new quantity =0
MessageBox.Show("You Didn't Enter A Valid Quantity. Quantity Changed Back To: " + singletonInstance.QuantityOriginal);
QuantityBoxLabel.Focus();
}
else
{
if (singletonInstance.UpdatedSuccessfully == false)
{
// new quantity !=0
//Test on Product ID:519
// Chnange to dynamic via SlectionIndex or anything..
//DISABLE FOR TESTING:
//using (MFTDataContext MFTdb = new MFTDataContext(strConnectionString))
//{
// var itemToChange = (from item in MFTdb.MFTCart
// where item.ProductID == singletonInstance.ItemToChange
// select item).Single();
// itemToChange.ProductQuantity = singletonInstance.QuantityChanged;
// itemToChange.ProductTotalPrice = singletonInstance.QuantityChanged * itemToChange.ProductPrice;
// MFTdb.SubmitChanges();
//}
singletonInstance.SomethingChanged = false;
singletonInstance.UpdatedSuccessfully = true;
}
else
{
}
(Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/Cart.xaml?refersh=" + DateTime.Now.ToString(), UriKind.Relative));
}
}
}
private void QuantityBoxLabel_LostFocus(object sender, RoutedEventArgs e)
{
// Do same as QuantityBoxLabel_MouseLeave
QuantityBoxLabel_MouseLeave(null, null);
}
private void QuantityBoxLabel_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
//Cant be 0 . Already Filtered in ThirdPage
if (QuantityBoxLabel.Text != "")
{
singletonInstance.QuantityOriginal = int.Parse(QuantityBoxLabel.Text);
}
}
private void QuantityBoxLabel_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
// TESTING;
// this.QuantityBoxLabel.IsHitTestVisible = false;
//Cant be 0 . Already Filtered in ThirdPage
singletonInstance.QuantityOriginal = int.Parse(QuantityBoxLabel.Text);
}
private void QuantityBoxLabel_LayoutUpdated(object sender, EventArgs e)
{
QuantityBoxLabel.Focus();
}
}
}