共用方式為


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

App 的顯示名稱。

範例

呼叫 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

備註

在某些情況下,使用者可能尚未安裝處理您要啟動之檔案的 app。 依照預設,Windows 處理這些情況的方法是提供連結,讓使用者在市集上搜尋適當的應用程式。 搭配 LauncherOptions.preferredApplicationDisplayNameLauncherOptions.preferredApplicationPackageFamilyName 搭配使用,在 Windows 市集中為使用者提供可取得以處理檔案的應用程式。 您使用的顯示名稱應該對應到 Windows 市集中應用程式的顯示名稱。

您必須設定這兩個慣用的應用程式屬性來建議應用程式。 只設定其中一個將出現錯誤。

注意

您無法同時設定慣用的應用程式屬性和後援 URI,因為只能使用一個後援。 如果同時設定兩個後援,啟動器 API 將會失敗。

重要

此屬性只會在桌面裝置上實作。

適用於

另請參閱