LauncherOptions.PreferredApplicationDisplayName Свойство

Определение

Возвращает или задает значение, представляющее отображаемое имя приложения в магазине, которое пользователь должен установить, если приложение не существует для обработки типа файла или 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

Значение свойства

String

Platform::String

winrt::hstring

Отображаемое имя приложения.

Примеры

Вызовите метод Launcher.LaunchFileAsync(IStorageFile, LauncherOptions) | launchFileAsync(IStorageFile, LauncherOptions) с параметром preferredApplicationDisplayName , для которого задано отображаемое имя приложения в Магазине Windows, а для параметра preferredApplicationPackageFamilyName — имя семейства пакетов приложения в Магазине Windows.

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

Комментарии

В некоторых случаях у пользователя может быть не установлено приложение для обработки запускаемого файла. Тогда по умолчанию Windows предоставит пользователю ссылку для поиска подходящего приложения в Магазине. Используйте LauncherOptions.PreferredApplicationDisplayName вместе с LauncherOptions.preferredApplicationPackageFamilyName , чтобы предоставить пользователю приложение в Магазине Windows, которое он может получить для обработки файла. Отображаемое имя должно соответствовать отображаемого имени приложения в Магазине Windows.

Чтобы рекомендовать приложение, необходимо задать оба этих предпочтительных свойства приложения. Настройка одного параметра без другого приведет к ошибке.

Примечание

Нельзя одновременно задать предпочтительные свойства приложения и резервный URI, так как можно использовать только один резервный вариант. Если заданы оба резервных варианта, API средства запуска завершится ошибкой.

Важно!

Это свойство реализовано только на настольных устройствах.

Применяется к

См. также раздел