。
我开始与.net Maui合作。我只是通过开始发展就遇到了一个问题。 我想展示弹出窗口,并且正在使用社区工具包。
我所做的只是:
我创建了一个新的.NET MAUI应用程序项目,安装了社区工具包Nuget软件包(当然,也在启动类中的.usemauicommunitytoolkit)并为弹出式添加了XAML文件:
<?xml version="1.0" encoding="utf-8" ?>
<toolkit:Popup xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
x:Class="TestApp.ProfilePopup">
<VerticalStackLayout>
<Label Text="This is a very important message!" />
</VerticalStackLayout>
</toolkit:Popup>
我没有partial类的for partial类。此弹出窗口
我刚刚修改了主页上的按钮以显示弹出窗口:
private void OnCounterClicked(object sender, EventArgs e)
{
var popup = new ProfilePopup();
this.ShowPopup(popup);
}
如果我运行此应用程序,然后单击按钮显示弹出窗口,我将获取错误消息:
communitytooltoolkit.maui.core.core.handlers.handlers.popuphandler在testapp.profilepopup不兼容
,
如果我在C#中创建弹出窗口,它有效:
private void OnCounterClicked(object sender, EventArgs e)
{
var popup = new Popup
{
Content = new VerticalStackLayout
{
Children =
{
new Label
{
Text = "This is a very important message!"
}
}
}
};
this.ShowPopup(popup);
}
知道我在做错什么吗?
谢谢你!
马克斯
I started working with .NET MAUI. I ran into a problem just by starting my development.
I want to show a popup and I'm using the Community Toolkit.
All I did is:
I created a new .NET MAUI Application Project, installed the Community Toolkit NuGet Package (of course also the .UseMauiCommunityToolkit in the start up class) and added a XAML File for the Popup:
<?xml version="1.0" encoding="utf-8" ?>
<toolkit:Popup xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
x:Class="TestApp.ProfilePopup">
<VerticalStackLayout>
<Label Text="This is a very important message!" />
</VerticalStackLayout>
</toolkit:Popup>
I've no partial class for this popup
I just modified the button on MainPage to display the popup:
private void OnCounterClicked(object sender, EventArgs e)
{
var popup = new ProfilePopup();
this.ShowPopup(popup);
}
If I run this application and click on the button to display the popup I'll get the error message:
CommunityToolkit.Maui.Core.Handlers.PopupHandler found for TestApp.ProfilePopup is incompatible
If I create the popup in C#, it works:
private void OnCounterClicked(object sender, EventArgs e)
{
var popup = new Popup
{
Content = new VerticalStackLayout
{
Children =
{
new Label
{
Text = "This is a very important message!"
}
}
}
};
this.ShowPopup(popup);
}
Any idea what I'm doing wrong?
Thank you!
Markus
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我复制了错误消息。
原因:“我没有这个弹出窗口的部分类” 。
那行不通。没有这些,就没有
initizecomponent
呼叫。结果不是有效的视图。要解决问题,
请首先确保您已在
mauiprogram.cs
中注册该工具包:然后,您必须具有
文件
profilepopup.xaml.cs
包含:我使用:我使用使用自定义视图生成自定义视图这些步骤:
myview.xaml
和myview.xaml.cs
。myview.xaml
中,添加所需的XMLN并更改基类。WAS:
更改为:
myview.xaml.cs
中,更改基类。是:
更改为:
I reproduced the error message.
THE CAUSE: "I've no partial class for this popup".
That won't work. without that, there is no
InitializeComponent
call. The result is not a valid View.To fix the problem,
First make sure you have got the toolkit registered in
MauiProgram.cs
:then you must have
file
ProfilePopup.xaml.cs
containing:I generate custom views using these steps:
MyView.xaml
andMyView.xaml.cs
.MyView.xaml
, add needed xmlns and change base class.Was:
change to:
MyView.xaml.cs
, change base class.Was:
change to:
我遇到了同样的问题。我忘了添加
.usemauicommunitytoolkit();
mauipragram.cs
。您也可以尝试一下:
I was having the same problem. I forgot to add
.UseMauiCommunityToolkit();
toMauiProgram.cs
.You can try this, as well: