【问题标题】:Open Windows Store with Xamarin Forms使用 Xamarin 表单打开 Windows 应用商店
【发布时间】:2017-08-09 12:19:42
【问题描述】:

我正在使用 C# 在 Xamarin Forms 上开发 Windows Phone 8 应用程序。

我需要在点击 DisplayAlert 后打开商店。

if (condition)
{
  await DisplayAlert(title,body,button);
  //link to store for upgrading the app version
}

但我陷入了困境,我无法对 displayalert 内的按钮进行“点击监听”,而且我不知道如何链接到它外面的商店(以一种残酷且不那么优雅的方式)

【问题讨论】:

  • await Windows.System.Launcher.LaunchUriAsync(new Uri(@"ms-windows-store://review/?ProductId=9wzdncrfj2wl")); 输入您的产品 ID。不确定它是否有效,但我发现了这个......docs.microsoft.com/en-us/windows/uwp/launch-resume/…
  • 它有点用,但不管我放什么ID,它总是打开音乐应用程序(这很有趣,因为它清楚地写着商店)

标签: c# xamarin windows-phone-8 xamarin.forms windows-store-apps


【解决方案1】:

但我陷入了困境,我无法对 displayalert 内的按钮进行“点击监听”,而且我不知道如何链接到它外面的商店(以一种残酷且不那么优雅的方式)

对于您的要求,您可以通过dependence service优雅地实现它。

public interface OpenStore
{
 Task<bool> OpenStore();
}

在您的客户端项目中实现OpenStore 接口。

[assembly:Dependency(typeof(IOpenStore))]

public class IOpenStore : OpenStore
{
    public async Task<bool> OpenStore()
    {
        var storeUri = new Uri("ms-windows-store://home");
        var success = await Windows.System.Launcher.LaunchUriAsync(storeUri);
        return success;
    }
}

用法

var answer = await DisplayAlert("Question?", "Would you like to open store", "Yes", "No");   
if (answer)
{
  await  DependencyService.Get<OpenStore>().OpenStore();
}

您的应用可以使用 ms-windows-store: URI 方案来启动 Windows 应用商店应用。打开产品详情页面、产品评论页面和搜索页面等。例如,以下 URI 打开 Windows 应用商店应用并启动应用商店的主页。

ms-windows-store://home/

欲了解更多信息,see Launch the Windows Store app

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-04
    • 1970-01-01
    相关资源
    最近更新 更多