0

I have the following XAML:

 <ContentPage.Content>
    <xct:Expander IsExpanded="true">
        <StackLayout>
            <xct:Expander.Header>
                <Label Text="{Binding Name}"/>
            </xct:Expander.Header>
            <xct:Expander.ContentTemplate>
                <Label Text="{Binding Item.Text}"/>
                <Button Text="doSomething" Command="{Binding command}"/>
            </xct:Expander.ContentTemplate>
        </StackLayout>
    </xct:Expander>
</ContentPage.Content>

And I get this error when compiling:

attachable property "Header" can't be found on type "Expander"

I have already installed Xamarin.CommunityToolkit package and added

     xmlns:xct="http://xamarin.com/schemas/2020/toolkit"

to the namespace.

I have also cleaned and rebuilded the project several times. Nothing works.

Any idea?

Mr Guliarte
  • 739
  • 1
  • 10
  • 27

1 Answers1

0

You can change the <xct:Expander.ContentTemplate> to StackLayout and remove the StackLayout outside to make the stacklayout the child of the expander. Here is the demo you can refer to.

<ContentPage.Content>
    <xct:Expander IsExpanded="true">
      
            <xct:Expander.Header>
                <Label Text="name"/>
            </xct:Expander.Header>
              
        <StackLayout> 
            <Label Text="Binding Item.Text"/>
            <Button Text="doSomething" Command="{Binding command}"/>
        </StackLayout>

    </xct:Expander>
</ContentPage.Content>
Guangyu Bai - MSFT
  • 2,555
  • 1
  • 2
  • 8