/// <summary>
        /// Sends a ink status query to the selected printer.
        /// </summary>
        /// <param name="sender" type = "Windows.UI.Xaml.Controls.Button">A pointer to the button that the user hit to enumerate printers</param>
        /// <param name="e">Arguments passed in by the event.</param>
        void GetInkStatus(object sender, RoutedEventArgs e)
        {
            if (AssociatedPrinters.Items.Count > 0)
            {
                // Get the printer that the user has selected to query.
                ComboBoxItem selectedItem = AssociatedPrinters.SelectedItem as ComboBoxItem;

                // The interfaceId is retrieved from the detail field.
                string interfaceId = selectedItem.DataContext as string;

                try
                {
                    // Unsubscribe existing ink level event handler, if any.
                    if (printHelper != null)
                    {
                        printHelper.OnInkLevelReceived -= OnInkLevelReceived;
                        printHelper = null;
                    }

                    object context = Windows.Devices.Printers.Extensions.PrintExtensionContext.FromDeviceId(interfaceId);

                    // Use the PrinterHelperClass to retrieve the bidi data and display it.
                    printHelper = new PrintHelperClass(context);
                    try
                    {
                        printHelper.OnInkLevelReceived += OnInkLevelReceived;
                        printHelper.SendInkLevelQuery();

                        rootPage.NotifyUser("Ink level query successful", NotifyType.StatusMessage);
                    }
                    catch (Exception)
                    {
                        rootPage.NotifyUser("Ink level query unsuccessful", NotifyType.ErrorMessage);
                    }
                }
                catch (Exception)
                {
                    rootPage.NotifyUser("Error retrieving PrinterExtensionContext from InterfaceId", NotifyType.ErrorMessage);
                }
            }
        }
        /// <summary>
        /// Handle the Print Task Setup Event
        /// </summary>
        /// <param name="sessionManager">Session manager</param>
        /// <param name="printTaskSetupArgs">Has the Configuration and Controller</param>
        internal void OnSetupRequested(PrintWorkflowForegroundSession sessionManager, PrintWorkflowForegroundSetupRequestedEventArgs printTaskSetupArgs)
        {
            // If anything asynchronous is going to be done, you need to take out a deferral here,
            // since otherwise the next callback happens once this one exits, which may be premature
            Deferral setupRequestedDeferral = printTaskSetupArgs.GetDeferral();

            // Get information about the source application, print job title, and session ID
            string sourceApplicationName = printTaskSetupArgs.Configuration.SourceAppDisplayName;
            string jobTitle  = printTaskSetupArgs.Configuration.JobTitle;
            string sessionId = printTaskSetupArgs.Configuration.SessionId;
            string localStorageVariablePrefix = string.Format("{0}::", sessionId);

            localStorage.SetStorageKeyPrefix(localStorageVariablePrefix);

            // Get the PrinterExtensionContextNative from the activation arguments
            IntPtr ptr = GetPrintWorkflowConfigurationNativeAsIntPtr(printTaskSetupArgs);

            // Create the Print Helper
            PrintHelperClass printHelper = new PrintHelperClass(InitializationType.PrinterExtensionContextNativeType, (ulong)ptr);

            printerName          = printHelper.GetPrinterName();
            WorkflowHeadingLabel = string.Format(workflowHeadingFormat, sourceApplicationName, printerName);

            // Add callback handler on main page
            try
            {
                printHelper.OnInkLevelReceived += OnQueryResultReceived;
                // Send the BiDi query
                printHelper.SendInkLevelQuery();
            }
            catch (Exception ex)
            {
                string errorMessage = ex.Message;
                Debug.WriteLine(errorMessage);
            }
            finally
            {
                // Complete the deferral taken out at the start of OnSetupRequested
                setupRequestedDeferral.Complete();
            }
        }