发布于 2025-02-05 03:44:29 字数 1554 浏览 1 评论 0原文

我开始与.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 技术交流群。

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

发布评论

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

评论(2

送你一个梦 2025-02-12 03:44:29

我复制了错误消息。

原因:“我没有这个弹出窗口的部分类”

那行不通。没有这些,就没有initizecomponent呼叫。结果不是有效的视图。


要解决问题,

请首先确保您已在mauiprogram.cs中注册该工具包:

using CommunityToolkit.Maui;
...

builder.UseMauiApp<App>().UseMauiCommunityToolkit();

然后,您必须具有

文件profilepopup.xaml.cs包含:

public partial class ProfilePopup : CommunityToolkit.Maui.Views.Popup
{
    public ProfilePopup()
    {
        InitializeComponent();
    }
}

我使用:我使用使用自定义视图生成自定义视图这些步骤:

  1. 项目 /添加新项目 / .NET MAUI ContentView(XAML)。
  2. 给名称“ myview”。这将两个文件添加到项目:myview.xamlmyview.xaml.cs
  3. myview.xaml中,添加所需的XMLN并更改基类。
    WAS:
<ContentView xmlns=...
    ...
    x:Class=...>
...
</ContentView>

更改为:

<toolkit:Popup xmlns=
    ...
    xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
    x:Class=...>
...
</toolkit:Popup>
  1. myview.xaml.cs中,更改基类。
    是:
public partial class ProfilePopup : ContentView

更改为:

public partial class ProfilePopup : CommunityToolkit.Maui.Views.Popup

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:

using CommunityToolkit.Maui;
...

builder.UseMauiApp<App>().UseMauiCommunityToolkit();

then you must have

file ProfilePopup.xaml.cs containing:

public partial class ProfilePopup : CommunityToolkit.Maui.Views.Popup
{
    public ProfilePopup()
    {
        InitializeComponent();
    }
}

I generate custom views using these steps:

  1. Project / Add New Item / .NET MAUI ContentView (XAML).
  2. Give name "MyView". This adds TWO files to project: MyView.xaml and MyView.xaml.cs.
  3. In MyView.xaml, add needed xmlns and change base class.
    Was:
<ContentView xmlns=...
    ...
    x:Class=...>
...
</ContentView>

change to:

<toolkit:Popup xmlns=
    ...
    xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
    x:Class=...>
...
</toolkit:Popup>
  1. In MyView.xaml.cs, change base class.
    Was:
public partial class ProfilePopup : ContentView

change to:

public partial class ProfilePopup : CommunityToolkit.Maui.Views.Popup
仲春光 2025-02-12 03:44:29

我遇到了同样的问题。我忘了添加.usemauicommunitytoolkit(); mauipragram.cs

您也可以尝试一下:

var popup = new PopupPage();
await PopupExtensions.ShowPopupAsync<PopupPage>(this, popup);

I was having the same problem. I forgot to add .UseMauiCommunityToolkit(); to MauiProgram.cs.

You can try this, as well:

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