xamarin / XamarinCommunityToolkit

The Xamarin Community Toolkit is a collection of Animations, Behaviors, Converters, and Effects for mobile development with Xamarin.Forms. It simplifies and demonstrates common developer tasks building iOS, Android, and UWP apps with Xamarin.Forms.
MIT License
1.58k stars 471 forks source link

[Bug] StateLayout doesn't work with ContentView #1773

Open czmirek opened 2 years ago

czmirek commented 2 years ago

Description

StateLayout works just with Grid or StackLayout...it doesn't work with ContentView, ScrollView, Frame and any other layout. Or the documentation is not very clear on how to use StateLayout with those layouts. Just that...

The StateLayout control enables the user to turn any layout element like a Grid or StackLayout into an individual state-aware element.

Stack Trace

Steps to Reproduce

<ContentView xct:StateLayout.CurrentState="{Binding LayoutState}">
    <xct:StateLayout.StateViews>
        <xct:StateView StateKey="Loading">
            <StackLayout VerticalOptions="Center" HorizontalOptions="Center">
                <ActivityIndicator Color="#1abc9c" />
                <Label Text="Loading..." HorizontalOptions="Center" />
            </StackLayout>
        </xct:StateView>
    </xct:StateLayout.StateViews>
</ContentView>

Expected Behavior

It works.

Actual Behavior

System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation.'

Basic Information

Workaround

I have to use Grid or StackLayout instead.

Reproduction imagery

FrozDark commented 2 years ago

Looking though the sourcecode of StateLayout it works with layouts that derives from Layout with multiple views like StackLayout, Grid and others.. Not working with layouts with single view like ContentView as you described.

From the doc

The StateLayout control enables the user to turn any layout element like a Grid or StackLayout into an individual state-aware element.

So it's seems the doc is not very clear to understand cause of words any layout but clarified the type of layouts

like a Grid or StackLayout

bijington commented 2 years ago

@czmirek that exception doesn't provide much help. Was there an InnerException and possibly a stack trace pointing to where the issue might lie?