使用 Xamarin 窗体打开 Windows 应用商店



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

我需要在点击显示警报后打开商店。

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

但是我被困在了这个,我无法对DisplayAlert内的按钮进行"点击监听",并且我不知道如何链接到它外面的商店(以一种残酷且不那么优雅的方式(

但我被困在了这个,我无法对 displayalert 内的按钮进行"点击监听",我不知道如何链接到它外面的商店(以一种残酷和不那么优雅的方式(

根据您的要求,您可以通过依赖服务优雅地实现它。

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/

有关详细信息,请参阅启动 Windows 应用商店应用。