Search code examples
xamlxamarin.formsexpanderxamarin-community-toolkit

Cannot resolve type 'Expander'


I have an Expander that no longer accepts the Expander value in the Binding in the AncestorType property. It used to work, but since I upgraded to Xamarin forms version 5.0.0 it doesn't work anymore and Visual Studio reports me the following error:

Error XFC0000 Cannot resolve type "Expander".

<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>

Solution

  • Since Expander is not defined in Xamarin.Forms, you need to specify that it is defined in xct namespace (from Expander was not found in Xamarin Forms 5.0.0) in your AncestorType, similar to when you consume it you don't do <Expander ..> but <xct:Expander ..>.

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