Cannot resolve type 'Expander'

Viewed 2570

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

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

Since XF 5.0, the Expander and MediaElement controls where moved to the Xamarin Community Toolkit package (you can find about this on the Xamarin.Forms 5 release notes).

Please install the Xamarin.Community.Toolkit package and resolve the reference on your ContentPage header in order to use the xct namespace.

Related