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

deyfvvtc  于 9个月前  发布在  其他
关注(0)|答案(1)|浏览(101)

在一个“弹出窗口”,我得到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;
        }

    }
}

更新以显示错误:


的数据


tpgth1q7

tpgth1q71#

我可以重现你的问题。我通过清理和重建解决了它。
然后将Xamarin.CommunityToolkit.UI.Views.Popup<AreaSelectedDtoModel>更改为Xamarin.CommunityToolkit.UI.Views.Popup

public partial class AreaSelectPopup : Xamarin.CommunityToolkit.UI.Views.Popup

字符串
弹出窗口中的传递参数:

Dismiss(Object parameter);


并获取页面中的参数:

var result = await Navigation.ShowPopupAsync(popup);

相关问题