在 MVVM Xamarin Forms 的“Popup”类型中找不到可附加属性

问题描述 投票:0回答:1

在“弹出窗口”中,我收到 3 条错误消息:

在“Popup”类型中找不到可附加属性“BindingContext”。

在“Popup”类型中找不到可附加属性“Resources”。

在“Popup”类型中找不到可附加属性“Content”。

而且我不知道如何解决。

XAML 代码:

<?xml version="1.0" encoding="utf-8" ?>
<xct:Popup xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:xct="clr-namespace:Xamarin.CommunityToolkit.UI.Views;assembly=Xamarin.CommunityToolkit"
             xmlns:areaSelectedDtoModel="clr-namespace:BlaBlaBla.Models.Dto;assembly=BlaBlaBla"
             Size="340,340"
             x:Class="BlaBlaBla.Popup.AreaSelectPopup"
             x:TypeArguments="areaSelectedDtoModel:AreaSelectedDtoModel"
             x:Name="XNameAreaSelectPopupPage"
             xmlns:viewModels="clr-namespace:BlaBlaBla.Models.View;assembly=BlaBlaBla"
             xmlns:behaviors="http://xamarin.com/schemas/2020/toolkit">

    <xct:Popup.BindingContext>
        <viewModels:AreaSelectPopupViewModel/>
    </xct:Popup.BindingContext>
    <xct:Popup.Resources>
        <ResourceDictionary>
            <behaviors:ItemSelectedEventArgsConverter x:Key="ItemSelectedEventArgsConverter"/>
        </ResourceDictionary>
    </xct:Popup.Resources>
    <xct:Popup.Content>
        
        ... Some code ....

    </xct:Popup.Content>
</xct:Popup>

CS 代码:

namespace BlaBlaBla.Popup
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class AreaSelectPopup : Xamarin.CommunityToolkit.UI.Views.Popup<AreaSelectedDtoModel>
    {

        public AreaSelectPopup(AreaSelectedDtoModel areaSelectedDto)
        {
            InitializeComponent();
            var bindingContext = BindingContext;
            var context = bindingContext as AreaSelectPopupViewModel;
        }

    }
}
xamarin xamarin.forms
1个回答
0
投票

我可以重现你的问题。我通过清理和重建解决了这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.