Expander direction error InvalidOperationException: Header not initialized

265 Views Asked by At

When set Expander direction an error message is displayed

System.InvalidOperationException: 'Header not initialized'

<xct:Expander Direction="Left">
    <xct:Expander.Header>
        <Label Text="H" TextColor="Black"/>
    </xct:Expander.Header>
    <StackLayout Orientation="Horizontal" >
        <Label Text="!" TextColor="Black" />
        <Label Text="D" TextColor="Red" />
    </StackLayout>
</xct:Expander>

The code works fine if there is no direction attribute.

2

There are 2 best solutions below

0
On BEST ANSWER

This is a known bug https://github.com/xamarin/XamarinCommunityToolkit/issues/1144 which has been fixed in this pr and will be available on a next release.

0
On

Setting the direction after the header definition made it works for me.

<xct:Expander>
    <xct:Expander.Header>
        <Label Text="H" TextColor="Black"/>
    </xct:Expander.Header>
    <xct:Expander.Direction>
        <xct:ExpandDirection>Left</xct:ExpandDirection>
    </xct:Expander.Direction>
    <StackLayout Orientation="Horizontal" >
        <Label Text="!" TextColor="Black" />
        <Label Text="D" TextColor="Red" />
    </StackLayout>
</xct:Expander>