简体   繁体   English

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

[英]Custom WinUI 3 C++/WinRT Control in C# WinUI project

I am trying to create WinUI C++/WinRT Component containing XAML control and iclude this custom control inside C# WinUI 3 project.我正在尝试创建包含 XAML 控件的 WinUI C++/WinRT 组件,并将此自定义控件包含在 C# WinUI 3 项目中。 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由于 WinUI 3 不提供媒体播放器,我想制作这样的媒体播放器: https://github.com/asklar/WinAppSDK-MediaPlayer

EDIT:编辑:

So far I found WinRT APIs not supported in .NET 5 or later .到目前为止,我发现.NET 5 或更高版本不支持 WinRT API I found there Windows.UI.Xaml (all classes in this namespace) which seems to be needed for creating custom c++/winrt control.我在那里找到了Windows.UI.Xaml(此命名空间中的所有类) ,这似乎是创建自定义 c++/winrt 控件所必需的。 After I read this I assume that it is not possible to consume custom C++/WinRT WinUI control in C# WinUI project.阅读本文后,我假设无法在 C# WinUI 项目中使用自定义 C++/WinRT WinUI 控件。

在此处输入图像描述

Example:例子:

Those are steps I created that projects.这些是我创建该项目的步骤。

  1. Create C# Library创建C#库
  2. Create WinUI C++ Component创建 WinUI C++ 组件
  3. Setup accordingly to MS Docs and Example根据 MS 文档和示例进行相应设置
  4. Add WindowsSdk reference to library project将 WindowsSdk 引用添加到库项目
  5. Add custom control to C++ project C++项目添加自定义控件

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.我发现可能的是在 WinUI C++/WinRT 项目中使用自定义 C# WinUI contron,这对我来说似乎是 go 的方式。

Issue should be fixed by updating Windows App SDK to 1.1.0-preview2.应通过将 Windows App SDK 更新到 1.1.0-preview2 来解决问题。 More information in this post .更多信息在这篇文章中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C# WinUI 项目,如何在同一个控件上添加多个 ExpressionAnimation? - C# WinUI project, How to add Multiple ExpressionAnimation on same control? C# UWP项目如何正确添加WinUI控件 - How correctly add WinUI control to C# UWP project C# 在 WinUI 3 中向 CustomControl 添加自定义事件 - C# Add custom event to a CustomControl in WinUI 3 如何在 Visual Studio 2022 中正确创建 C# WinUI 项目? - How to properly create a C# WinUI project in Visual Studio 2022? 带有 C# 的 WinUI 3 中的 WM_GETMINMAXINFO? - WM_GETMINMAXINFO in WinUI 3 with C#? WinUI 3.0 桌面 - C# 页面导航 - WinUI 3.0 Desktop - C# Page Navigation WinUI 3 - 单击用户控件c#中的按钮后如何在页面中打开控件? - WinUI 3 - How to open a control in a page upon click of button from a User Control c#? C# WPF/WinUI 从随机字母显示到文字显示效果 XAML TextBlock 控件 - C# From random letters displaying to a text reveal effect for WPF/WinUI XAML TextBlock control C# WinUI3 桌面:如何引用或控制 ListView 的所选项目 DataTemplate 中的按钮? - C# WinUI3 Desktop: How can I reference or control a button in a ListView's selected item DataTemplate? 如何从 WinUI3 C# 应用程序写入 HKEY_CURRENT_USER\\Control Panel\\Desktop\\WindowMetrics - How to write to HKEY_CURRENT_USER\\Control Panel\\Desktop\\WindowMetrics from WinUI3 C# app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM