C# WinUI 项目中的自定义 WinUI 3 C++/WinRT 控件
我正在尝试创建包含 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 项目中的控件。
示例:
这些是我创建该项目的步骤。
- 创建 C# 库
- 创建 WinUI C++ 进行组件
- 根据 MS 文档和示例
- 设置将 WindowsSdk 引用添加到库项目
- 将自定义控件添加到 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.
Example:
Those are steps I created that projects.
- Check this topic MS Docs
- Link to example
- Create C# Library
- Create WinUI C++ Component
- Setup accordingly to MS Docs and Example
- Add WindowsSdk reference to library project
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
应通过将 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.