C# WinUI 项目中的自定义 WinUI 3 C++/WinRT 控件

发布于 2025-01-16 21:11:04 字数 1305 浏览 1 评论 0原文

我正在尝试创建包含 XAML 控件的 WinUI C++/WinRT 组件,并将此自定义控件包含在 C# WinUI 3 项目中。这有可能吗?我还没有运气。如果可能的话,您能否提供一些例子?

原因:

由于WinUI 3不提供媒体播放器,我想制作这样的媒体播放器: https://github.com/asklar/WinAppSDK-MediaPlayer

编辑:

到目前为止我发现 <一个href="https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/desktop-to-uwp-enhance#winrt-apis-not-supported-in-net-5-or-later " rel="nofollow noreferrer">.NET 5 或更高版本不支持 WinRT API。我发现Windows.UI.Xaml(此命名空间中的所有类)似乎是创建自定义 c++/winrt 控件所需要的。读完本文后,我认为不可能使用自定义 C++/WinRT WinUI C# WinUI 项目中的控件。

输入图片此处描述

示例:

这些是我创建该项目的步骤。

  1. 创建 C# 库
  2. 创建 WinUI C++ 进行组件
  3. 根据 MS 文档和示例
  4. 设置将 WindowsSdk 引用添加到库项目
  5. 将自定义控件添加到 C++ 项目

我发现可能的是在 WinUI C++/WinRT 项目中使用自定义 C# WinUI 控件,这对我来说似乎是一种可行的方法。

I am trying to create WinUI C++/WinRT Component containing XAML control and iclude this custom control inside C# WinUI 3 project. Is this somehow possible? I had no luck yet. Could you please provide some examples if this is possible?

Reason:

Since WinUI 3 does not offer media player I want to make media player like this:
https://github.com/asklar/WinAppSDK-MediaPlayer

EDIT:

So far I found WinRT APIs not supported in .NET 5 or later. I found there Windows.UI.Xaml (all classes in this namespace) which seems to be needed for creating custom c++/winrt control. After I read this I assume that it is not possible to consume custom C++/WinRT WinUI
control in C# WinUI project.

enter image description here

Example:

Those are steps I created that projects.

  1. Create C# Library
  2. Create WinUI C++ Component
  3. Setup accordingly to MS Docs and Example
  4. Add WindowsSdk reference to library project
  5. Add custom control to C++ project

What I found possible is to consume custom C# WinUI contron inside WinUI C++/WinRT project, which seems to be way to go for me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怪我闹别瞎闹 2025-01-23 21:11:04

应通过将 Windows App SDK 更新到 1.1.0-preview2 来修复问题。更多信息请参阅此帖子

Issue should be fixed by updating Windows App SDK to 1.1.0-preview2. More information in this post.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文