你好,@于晟。欢迎来到 Microsoft 问答。
你可以按如下方式在WPF项目中使用Windows.Services.Store
步骤1:配置 WPF 项目以提供 Windows App SDK 支持
在.csproj文件中PropertyGroup位置下添加以下配置(假设你的项目是.Net 8 ,目标环境是Windows 11)
<PropertyGroup>
<TargetFramework>net8.0-windows10.0.22000.0</TargetFramework>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<WindowsPackageType>None</WindowsPackageType>
</PropertyGroup>
官方文档: 1.配置 WPF 项目以提供 Windows App SDK 支持
2.目标框架名字对象
步骤2:通过NuGet安装Microsoft.WindowsAppSDK
步骤3:下载并安装WindowsAppRuntime
: WindowsAppRuntime下载位置
步骤4:引用Windows.Services.Store
,获取StoreContext
并配置
using Windows.Services.Store;
private async void PayMent_Button(object sender, RoutedEventArgs e)
{
StoreContext context = StoreContext.GetDefault();
// Obtain window handle by passing in pointer to the window object
var hwnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;
// Initialize the dialog using wrapper function for IInitializeWithWindow
WinRT.Interop.InitializeWithWindow.Initialize(context, hwnd);
}
官方文档: 1.将 StoreContext 类与桌面桥配合使用
如果答案是正确的,请点击“接受答案”并点赞。 如果您对此答案还有其他疑问,请点击“评论”。
注意:如果您想接收相关电子邮件,请按照我们的文档中的步骤启用电子邮件通知 此线程的通知。