Share via


LauncherOptions.PreferredApplicationDisplayName Proprietà

Definizione

Ottiene o imposta un valore che rappresenta il nome visualizzato dell'app nello Store che l'utente deve installare se non esiste alcuna app per gestire il tipo di file o l'URI.

public:
 property Platform::String ^ PreferredApplicationDisplayName { Platform::String ^ get(); void set(Platform::String ^ value); };
winrt::hstring PreferredApplicationDisplayName();

void PreferredApplicationDisplayName(winrt::hstring value);
public string PreferredApplicationDisplayName { get; set; }
var string = launcherOptions.preferredApplicationDisplayName;
launcherOptions.preferredApplicationDisplayName = string;
Public Property PreferredApplicationDisplayName As String

Valore della proprietà

String

Platform::String

winrt::hstring

Nome visualizzato dell'app.

Esempio

Chiamare il metodo Launcher.LaunchFileAsync(IStorageFile, LauncherOptions) | launchFileAsync(IStorageFile, LauncherOptions) con preferredApplicationDisplayName impostato sul nome visualizzato di un'app in Windows Store e il valore preferredApplicationPackageFamilyName impostato sul nome della famiglia di pacchetti di un'app in Windows Store.

async void DefaultLaunch()
{
   // Path to the file in the app package to launch
   string imageFile = @"images\test.png";

   // Get the image file from the package's image directory
   var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile);

   if (file != null)
   {
      // Set the recommended app
      var options = new Windows.System.LauncherOptions();
      options.PreferredApplicationPackageFamilyName = "Contoso.FileApp_8wknc82po1e";
      options.PreferredApplicationDisplayName = "Contoso File App";


      // Launch the retrieved file pass in the recommended app 
      // in case the user has no apps installed to handle the file
      bool success = await Windows.System.Launcher.LaunchFileAsync(file, options);
      if (success)
      {
         // File launched
      }
      else
      {
         // File launch failed
      }
   }
   else
   {
      // Could not find file
   }
}
Windows::Foundation::IAsyncAction MainPage::DefaultLaunch()
{
    // Get the app's installation folder.
    Windows::Storage::StorageFolder installFolder{ Windows::ApplicationModel::Package::Current().InstalledLocation() };

    Windows::Storage::StorageFile file{ co_await installFolder.GetFileAsync(L"Assets\\LockScreenLogo.scale-200.png") };

    if (file)
    {
        // Set the recommended app.
        Windows::System::LauncherOptions launcherOptions;
        launcherOptions.PreferredApplicationPackageFamilyName(L"Contoso.FileApp_8wknc82po1e");
        launcherOptions.PreferredApplicationDisplayName(L"Contoso File App");

        // Launch the retrieved file.
        bool success{ co_await Windows::System::Launcher::LaunchFileAsync(file, launcherOptions) };
        if (success)
        {
            // File launched.
        }
        else
        {
            // File launch failed.
        }
    }
    else
    {
        // Couldn't find file.
    }
}
void MainPage::DefaultLaunch()
{
   auto installFolder = Windows::ApplicationModel::Package::Current->InstalledLocation;

   concurrency::task<Windows::Storage::StorageFile^> getFileOperation(installFolder->GetFileAsync("images\\test.png"));
   getFileOperation.then([](Windows::Storage::StorageFile^ file)
   {
      if (file != nullptr)
      {
         // Set the recommended app
         auto launchOptions = ref new Windows::System::LauncherOptions();
         launchOptions->PreferredApplicationPackageFamilyName = "Contoso.FileApp_8wknc82po1e";
         launchOptions->PreferredApplicationDisplayName = "Contoso File App";

         // Launch the retrieved file pass in the recommended app 
         // in case the user has no apps installed to handle the file
         concurrency::task<bool> launchFileOperation(Windows::System::Launcher::LaunchFileAsync(file, launchOptions));
         launchFileOperation.then([](bool success)
         {
            if (success)
            {
               // File launched
            }
            else
            {
               // File launch failed
            }
         });
      }
      else
      {
         // Could not find file
      }
   });
}
async Sub DefaultLaunch()

   ' Path to the file in the app package to launch
   Dim imageFile = "images\test.png"

   ' Get the image file from the package's image directory
   Dim file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(imageFile)

   If file IsNot Nothing Then
      ' Set the recommended app
      Dim options = Windows.System.LauncherOptions()
      options.PreferredApplicationPackageFamilyName = "Contoso.FileApp_8wknc82po1e";
      options.PreferredApplicationDisplayName = "Contoso File App";

      ' Launch the retrieved file pass in the recommended app 
      ' in case the user has no apps installed to handle the file
      Dim success = await Windows.System.Launcher.LaunchFileAsync(file)

      If success Then
         ' File launched
      Else
         ' File launch failed
      End If
   Else
      ' Could not find file
   End If
End Sub

Commenti

In alcuni casi è possibile che nel computer dell'utente non sia installata un'app per gestire il file da avviare. Per impostazione predefinita, Windows gestirà questi casi fornendo all'utente un link per cercare un'app appropriata in Windows Store. Usa LauncherOptions.PreferredApplicationDisplayName insieme a LauncherOptions.preferredApplicationPackageFamilyName per fornire all'utente un'app in Windows Store che può acquisire per gestire il file. Il nome visualizzato usato deve corrispondere al nome visualizzato dell'app in Windows Store.

È necessario impostare entrambe queste proprietà dell'applicazione preferite per consigliare un'app. Se ne imposti una senza impostare l'altra, si verificherà un errore.

Nota

Non è possibile impostare contemporaneamente le proprietà dell'applicazione preferite e l'URI di fallback, perché è possibile usare un solo fallback. L'API Launcher avrà esito negativo se vengono impostati entrambi i fallback.

Importante

Questa proprietà viene implementata solo nei dispositivi desktop.

Si applica a

Vedi anche