UWP打印支持应用(Print Support App)中虚拟打印机无法显示的问题求助
UWP打印支持应用(Print Support App)中虚拟打印机无法显示的问题求助
各位大佬好,我是第一次尝试开发UWP的打印支持应用(Print Support App),目标是做一个能在Windows打印对话框里选中的虚拟打印机(命名为MyCustomPrinter,配置在Package.appxmanifest里),但现在打印机完全没出现在设备列表里。微软的Print Support App设计文档看得我一头雾水,完全摸不着门路,实在没办法了来求助大家。
我是用Visual Studio 2022创建的「Blank App (Universal Windows)」项目,现在把我目前的代码和配置都贴出来,麻烦帮我看看哪里出问题了,有没有遗漏什么关键配置?
App.xaml
<Application x:Class="PrintingApp.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:PrintingApp"> </Application>
App.xaml.cs
using Windows.ApplicationModel.Activation; using Windows.Foundation; using Windows.Graphics.Printing.PrintSupport; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; namespace PrintingApp { /// <summary> /// Provides application-specific behavior to supplement the default <see cref="Application"/> class. /// </summary> sealed partial class App : Application { Deferral settingsDeferral; protected override void OnActivated(IActivatedEventArgs args) { if (args.Kind == ActivationKind.PrintSupportSettingsUI) { // Get the activation arguments var settingsEventArgs = args as PrintSupportSettingsActivatedEventArgs; PrintSupportSettingsUISession settingsSession = settingsEventArgs.Session; // Take deferral this.settingsDeferral = settingsEventArgs.GetDeferral(); // Create root frame var rootFrame = new Frame(); // Choose the page to be shown based upon where the application is being launched from switch (settingsSession.LaunchKind) { case SettingsLaunchKind.UserDefaultPrintTicket: { // Show settings page when launched for default printer settings rootFrame.Navigate(typeof(DefaultSettingsView), settingsSession); } break; case SettingsLaunchKind.JobPrintTicket: { // Show settings page when launched from printing app rootFrame.Navigate(typeof(MainPage), settingsSession); } break; } Window.Current.Content = rootFrame; } } internal void ExitSettings() { settingsDeferral.Complete(); } } }
Package.appxmanifest
<?xml version="1.0" encoding="utf-8"?> <Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:uap11="http://schemas.microsoft.com/appx/manifest/uap/windows10/11" xmlns:printsupport="http://schemas.microsoft.com/appx/manifest/printsupport/windows10" xmlns:printsupport2="http://schemas.microsoft.com/appx/manifest/printsupport/windows10/2" xmlns:desktop4="http://schemas.microsoft.com/appx/manifest/desktop/windows10/4" xmlns:iot2="http://schemas.microsoft.com/appx/manifest/iot/windows10/2" IgnorableNamespaces="uap mp desktop4 iot2 printsupport printsupport2 uap11"> <Identity Name="bc0e7b39-aec8-4569-85ad-b42b6da40308" Publisher="CN=CrazyEight" Version="1.0.0.0" /> <mp:PhoneIdentity PhoneProductId="bc0e7b39-aec8-4569-85ad-b42b6da40308" PhonePublisherId="00000000-0000-0000-0000-000000000000"/> <Properties> <DisplayName>PrintingApp</DisplayName> <PublisherDisplayName>CrazyEight</PublisherDisplayName> <Logo>Assets\StoreLogo.png</Logo> </Properties> <Dependencies> <TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" /> </Dependencies> <Resources> <Resource Language="x-generate"/> </Resources> <Applications> <Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="PrintingApp.App" desktop4:SupportsMultipleInstances="true" iot2:SupportsMultipleInstances="true"> <uap:VisualElements DisplayName="PrintingApp" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="PrintingApp" BackgroundColor="transparent"> <uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"/> <uap:SplashScreen Image="Assets\SplashScreen.png" /> </uap:VisualElements>
(注:我的Package.appxmanifest内容可能有点截断,但关键配置部分应该都在上面了)
麻烦各位帮我看看,是不是哪里没配置对,或者少了什么必须的步骤才导致虚拟打印机不显示?谢谢大家了!
内容来源于stack exchange
相关产品推荐
相关产品推荐

