无法解析类型“扩展器”

问题描述

我有一个扩展器,它不再接受 AncestorType 属性的绑定中的扩展器值。它曾经可以工作,但自从我升级到 Xamarin 表单 5.0.0 版后,它不再工作,并且 Visual Studio 报告了以下错误

错误 XFC0000 无法解析类型“扩展器”。

<xct:Expander.Header>
        <Image Source="ExpanderPlus.png" WidthRequest="30" HeightRequest="30" Rotation="180">
             <Image.Triggers>
                    <DataTrigger targettype="Image"
                                 Binding="{Binding Source={RelativeSource AncestorType={x:Type Expander}},Path=IsExpanded}"
                                 Value="True">
                            <Setter Property="Source" Value="ExpanderClose.png"/>
                    </DataTrigger>
             </Image.Triggers>
        </Image>
</xct:Expander.Header>

解决方法

自 XF 5.0 起,ExpanderMediaElement 控件移至 Xamarin Community Toolkit 包(您可以在 Xamarin.Forms 5 release notes 上找到相关信息)。

请安装 Xamarin.Community.Toolkit 包并解析 ContentPage 标头上的引用,以便使用 xct 命名空间。

,

由于 Expander 未在 Xamarin.Forms 中定义,您需要指定它在 xct 中的 AncestorType 命名空间(来自 Expander was not found in Xamarin Forms 5.0.0)中定义,类似于当你消费它时,你不做<Expander ..>而是<xct:Expander ..>

xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
Binding="{Binding Source={RelativeSource AncestorType={x:Type xct:Expander}},Path=IsExpanded}" Value="True">

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...