我可以在MAUI项目中使用现有的Winui3控件吗?
是否可以在毛伊岛项目中使用Winui 3的易位控件?喜欢
。到我的MAUI项目
<ItemGroup>
<PackageReference Include="Microsoft.UI.Xaml" Version="2.7.1" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.1.1" />
</ItemGroup>
并编辑app.xaml
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiWithWinui"
xmlns:controls="using:Microsoft.UI.Xaml.Controls"
x:Class="MauiWithWinui.App">
<Application.Resources>
<controls:XamlControlsResources>
<controls:XamlControlsResources.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
</controls:XamlControlsResources.MergedDictionaries>
</controls:XamlControlsResources>
</Application.Resources>
</Application>
以及platform/windows/app.xaml
,
<maui:MauiWinUIApplication
x:Class="MauiWithWinui.WinUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:maui="using:Microsoft.Maui"
xmlns:local="using:MauiWithWinui.WinUI"
xmlns:controls="using:Microsoft.UI.Xaml.Controls">
<Application.Resources>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/>
</Application.Resources>
</maui:MauiWinUIApplication>
但是当我在毛ui页面下使用winui控件时,提示无法找到该控件
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="using:Microsoft.UI.Xaml.Controls"
x:Class="MauiWithWinui.MainPage">
<Grid>
<controls:RatingControl AutomationProperties.Name="RatingControl with placeholder" PlaceholderValue="3" />
</Grid>
</ContentPage>
毛友项目仅针对Windows平台,尽管我知道Winui3项目是一个更好的选择
Is it possible to use the exisiting controls of WinUI 3 in the MAUI project? Like controls in https://github.com/microsoft/WinUI-Gallery
I installed the WinUI package to my MAUI project
<ItemGroup>
<PackageReference Include="Microsoft.UI.Xaml" Version="2.7.1" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.1.1" />
</ItemGroup>
And edit the App.xaml
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiWithWinui"
xmlns:controls="using:Microsoft.UI.Xaml.Controls"
x:Class="MauiWithWinui.App">
<Application.Resources>
<controls:XamlControlsResources>
<controls:XamlControlsResources.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
</controls:XamlControlsResources.MergedDictionaries>
</controls:XamlControlsResources>
</Application.Resources>
</Application>
as well as Platform/Windows/App.xaml
<maui:MauiWinUIApplication
x:Class="MauiWithWinui.WinUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:maui="using:Microsoft.Maui"
xmlns:local="using:MauiWithWinui.WinUI"
xmlns:controls="using:Microsoft.UI.Xaml.Controls">
<Application.Resources>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/>
</Application.Resources>
</maui:MauiWinUIApplication>
but when I went to use the WinUI control under a Page of MAUI, it prompted that the control could not be found
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="using:Microsoft.UI.Xaml.Controls"
x:Class="MauiWithWinui.MainPage">
<Grid>
<controls:RatingControl AutomationProperties.Name="RatingControl with placeholder" PlaceholderValue="3" />
</Grid>
</ContentPage>
the MAUI project only targeted to windows platform, though i know winui3 project is a better choice
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在混合框架。如果您想使用Winui控件,那么您几乎是正确的,除了将Winui控件添加到Maui XAML中的最后一步。
您需要做的是创建一个位于MAUI页面和平台视图之间的处理程序: https://github.com /Mattleibow/MauiwinuiratingControldeMo
这是原因是该代码还将在Android上运行,因此还需要做某事。如果您现在尝试为Android构建代码,那么甚至不可能编译。毛伊岛坐在之间,形成了一个抽象,可让您为每个平台做其他事情。
如果使用处理程序在Windows上运行我的代码,则将获得评级控件。如果您在Android上运行它,则会将获得空白视图,因为尚未创建Android处理程序。然后,您可以决定如何为Android或iOS制作此处理程序,并相应地将事件和属性连接起来。
You are mixing frameworks. If you want to use a WinUI control, you are almost right except for the last step where you are adding the WinUI control into Maui XAML.
What you need to do is create a handler that sits between the maui page and the platform view: https://github.com/mattleibow/MauiWinUIRatingControlDemo
Th reason this is needed is that this code will also run on Android, so that needs to also do something. If you try build your code for Android now, it is impossible to even compile. MAUI sits in between and forms an abstraction that allows you do something else for each platform.
If you run my code on Windows with the handler, you get the rating control. If you run it on Android, you get a blank view as the Android handler is not yet created. You can then decide how you want to make this handler for Android or iOS and hook up events and properties accordingly.