コード例 #1
0
ファイル: InkLevel.xaml.cs プロジェクト: mbin/Win81App
 /// <summary>
 /// Invoked when this page is navigated away from.
 /// </summary>
 /// <param name="e">Event data that describes how this page was reached.  The Parameter
 /// property is typically used to configure the page.</param>
 protected override void OnNavigatedFrom(NavigationEventArgs e)
 {
     // Unsubscribe from the OnInkLevelReceived event.
     if (printHelper != null)
     {
         printHelper.OnInkLevelReceived -= OnInkLevelReceived;
         printHelper = null;
     }
 }
コード例 #2
0
        public Preferences()
        {
            this.InitializeComponent();

            configuration = rootPage.Config;
            printerExtensionContext = rootPage.Context;
            printHelper = new PrintHelperClass(printerExtensionContext);

            // Disable scenario navigation by hiding the scenario list UI elements
            ((UIElement)rootPage.FindName("Scenarios")).Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            ((UIElement)rootPage.FindName("ScenarioListLabel")).Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            ((UIElement)rootPage.FindName("DescriptionText")).Visibility = Windows.UI.Xaml.Visibility.Collapsed;

            DisplaySettings();
        }
コード例 #3
0
ファイル: InkLevel.xaml.cs プロジェクト: mbin/Win81App
        /// <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);
                }
            }
        }