// handles when the user selects a product private void ProductsListBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { if (ProductsListBox.SelectedIndex == -1) { return; } StatusBar.BeginUpdateMessage("Loading selected product details..."); ThreadPool.QueueUserWorkItem(OnProductChangedWorker, ProductsListBox.SelectedItem); }
// handles when the user selects a category, all matching products are retrieved and displayed private void ProductCategoriesListBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { if (ProductCategoriesListBox.SelectedIndex == -1) { return; } // no product selected ProductDetails.DataContext = null; // load all products for selected category StatusBar.BeginUpdateMessage("Loading products for selected category..."); ThreadPool.QueueUserWorkItem(OnProductCategoryChangedWorker, ProductCategoriesListBox.SelectedItem); }
public MainPage() { // Required to initialize variables InitializeComponent(); // init the application StatusBar.BeginUpdateMessage("Initalizing application..."); _syncContext = SynchronizationContext.Current; // establish link to the status panel with the details panel ProductDetails.StatusBarPanel = StatusBar; // load product categories StatusBar.BeginUpdateMessage("Loading product categories..."); LoadProductCategories(); }
// get list of all products private void ProductCategoryListBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { StatusBar.BeginUpdateMessage("Loading products for selected category..."); ProductDetails.ResetProductDetails(); // get the selected item if (ProductCategoryListBox.SelectedIndex > -1) { ListItem category = (ListItem)ProductCategoryListBox.SelectedItem; CamlQuery query = new CamlQuery(); query.ViewXml = "<View><Query><Where><Eq><FieldRef Name='Category' /><Value Type='Lookup'>" + category["Title"] + "</Value></Eq></Where><OrderBy><FieldRef Name='Title' /></OrderBy></Query></View>"; List productList = Global.GetClientContext().Web.Lists.GetByTitle("Products"); _products = productList.GetItems(query); Global.GetClientContext().Load(_products); Global.GetClientContext().ExecuteQueryAsync(OnSucceededListenerGetProducts, OnFailListener); } }
// handles event when the connected status changes private void MainWindow_ConnectedStatusChanged(object sender, EventArgs e) { if (this.IsConnected) { // disable the url textbox WingtipSiteUrlTextBox.IsEnabled = false; StatusBar.BeginUpdateMessage("Loading product categories..."); ThreadPool.QueueUserWorkItem(LoadProductCategories); } else { // disable the url textbox WingtipSiteUrlTextBox.IsEnabled = true; // reset & disable categoties & product list boxes ProductCategoriesListBox.DataContext = null; ProductsListBox.DataContext = null; } }
// get product details private void ProductListBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { if (ProductListBox.SelectedIndex == -1) { return; } StatusBar.BeginUpdateMessage("Loading selected product details..."); // get the selected item ListItem selectedProduct = (ListItem)ProductListBox.SelectedItem; CamlQuery query = new CamlQuery(); query.ViewXml = "<View><Query><Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + selectedProduct["Title"] + "</Value></Eq></Where></Query></View>"; List productList = Global.GetClientContext().Web.Lists.GetByTitle("Products"); _products = productList.GetItems(query); Global.GetClientContext().Load(_products); Global.GetClientContext().ExecuteQueryAsync(OnSucceededListenerGetProductDetails, OnFailListener); }
// handles the click event when user connects to a site private void ConnectSiteButton_Click(object sender, System.Windows.RoutedEventArgs e) { if (!this.IsConnected) { // disable UI and show it's working WingtipSiteUrlTextBox.IsEnabled = false; ConnectSiteButton.IsEnabled = false; Cursor = Cursors.Wait; StatusBar.BeginUpdateMessage("Connecting to remote SharePoint site..."); ThreadPool.QueueUserWorkItem(OnConnectSiteButtonWorker, WingtipSiteUrlTextBox.Text); } else { Globals.ClientContext = null; this.IsConnected = false; ConnectSiteButton.Content = "Connect to SharePoint Site"; StatusBar.EndUpdateMessage(); // raise event that the connected status changed OnConnectedStatusChanged(new EventArgs()); } }