4

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>
Cfun
  • 8,442
  • 4
  • 30
  • 62
signalover
  • 167
  • 2
  • 7
  • how are you setting the `xct` namespace is your XAML? – Jason Feb 15 '21 at 19:23
  • 2
    Does this answer your question? [Expander was not found in Xamarin Forms 5.0.0](https://stackoverflow.com/questions/66212347/expander-was-not-found-in-xamarin-forms-5-0-0) – Shaw Feb 15 '21 at 20:20

2 Answers2

5

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">
Cfun
  • 8,442
  • 4
  • 30
  • 62
2

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.

FabriBertani
  • 1,606
  • 13
  • 24
  • 1
    The OP have already installed it following-up https://stackoverflow.com/q/66212347 the issue is in `AncestorType` and not in the way he consumed/instantiate control – Cfun Feb 15 '21 at 20:51