/// <summary>
        /// MainPage's Loaded event handler. Upon the child controls being laid
        /// out and ready to work with we set the default selected header, set
        /// up our Context and Site properties. And then get a list of
        /// Incidents from the SharePoint site.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            this._selectedHeader = this.hdrTotal;

            // Set up the Context and Site propeties
            _context = new ClientContext("http://data.contoso.com/");
            _site    = _context.Web;

            // Get the items in the Incidents list. We follow the pattern
            // identified in the associated white paper.
            // Specifically:
            // 1. Get a reference to the logical object to work with
            // 2. Set up the action to perform
            // 3. Execute the action, providing callback methods for
            //    success and failure.

            // 1. Get a reference to the logical object to work with, in this
            //    case our "Incidents" list
            List list = _site.Lists.GetByTitle("Incidents");

            // 2. Set up the action to perform. In this case set up our query,
            CamlQuery query = new CamlQuery();

            // 3. Execute the action, providing callback methods
            _incidentListItems = list.GetItems(query);
            _context.Load(_incidentListItems);
            _context.ExecuteQueryAsync(
                onGetIncidentsSucceeded,
                onGetIncidentsFailed
                );
        }
        /// <summary>
        /// Click handler for one of the Status items being clicked on. Updates
        /// the list of incidents to show only the ones with that particular
        /// status.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Status_Click(object sender, MouseButtonEventArgs e)
        {
            // Get a typed reference to the sender and verify that the user
            // didn't click on the already selected status to ensure we don't
            // take an unnecessary performance hit.
            StatusHeader header = (StatusHeader)sender;

            if (header.Status.Equals(this._selectedHeader.Status))
            {
                return;
            }


            // Set the previously selected header's Selected property to false,
            // set the _selectedHeader to the one just clicked, and then set
            // the Selected property on the newly selected StatusHeader to true
            this._selectedHeader.Selected = false;
            this._selectedHeader          = header;
            this._selectedHeader.Selected = true;

            // Reset the ItemsSource for the DataGrid that is displaying the
            // incidents. If the user clicked on the "Total" StatusHeader then
            // display all incidents that don't have a status of closed
            // otherwise find the incidents whose status matches that of the
            // clicked one.
            if (header.Status.Equals("Total"))
            {
                grdIncidents.ItemsSource = from incident in _incidents
                                           where !incident.Status.Equals("Closed")
                                           select incident;
            }
            else
            {
                grdIncidents.ItemsSource = from incident in _incidents
                                           where incident.Status.Equals(header.Status)
                                           select incident;
            }
        }
 public void InitializeComponent()
 {
     if (_contentLoaded)
     {
         return;
     }
     _contentLoaded = true;
     System.Windows.Application.LoadComponent(this, new System.Uri("/Contoso.IncidentDashboard;component/MainPage.xaml", System.UriKind.Relative));
     this.LayoutRoot          = ((System.Windows.Controls.Grid)(this.FindName("LayoutRoot")));
     this.hdrNewClaims        = ((Contoso.IncidentDashboard.StatusHeader)(this.FindName("hdrNewClaims")));
     this.hdrAgentAssigned    = ((Contoso.IncidentDashboard.StatusHeader)(this.FindName("hdrAgentAssigned")));
     this.hdrClaimApproved    = ((Contoso.IncidentDashboard.StatusHeader)(this.FindName("hdrClaimApproved")));
     this.hdrBidReceived      = ((Contoso.IncidentDashboard.StatusHeader)(this.FindName("hdrBidReceived")));
     this.hdrShopAssigned     = ((Contoso.IncidentDashboard.StatusHeader)(this.FindName("hdrShopAssigned")));
     this.hdrRepairComplete   = ((Contoso.IncidentDashboard.StatusHeader)(this.FindName("hdrRepairComplete")));
     this.hdrTotal            = ((Contoso.IncidentDashboard.StatusHeader)(this.FindName("hdrTotal")));
     this.grdIncidents        = ((System.Windows.Controls.DataGrid)(this.FindName("grdIncidents")));
     this.pnlPop              = ((System.Windows.Controls.Canvas)(this.FindName("pnlPop")));
     this.popMenu             = ((System.Windows.Controls.Primitives.Popup)(this.FindName("popMenu")));
     this.pnlBodyContents     = ((System.Windows.Controls.StackPanel)(this.FindName("pnlBodyContents")));
     this.bttnPrint           = ((System.Windows.Controls.Button)(this.FindName("bttnPrint")));
     this.bttnCopyToClipboard = ((System.Windows.Controls.Button)(this.FindName("bttnCopyToClipboard")));
 }