问题描述
我有一个扩展器,它不再接受 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 起,Expander
和 MediaElement
控件移至 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">