Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 81910

All views inside CarouselView are null

$
0
0

I have defined a CarouselView in XAML as follows:

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:controls="clr-namespace:CarouselView.FormsPlugin.Abstractions;assembly=CarouselView.FormsPlugin.Abstractions"
    x:Class="Youni.PresentationPage">
    <controls:CarouselViewControl
        x:Name="Carousel"
        Orientation="Vertical"
        IsSwipingEnabled="false"
        VerticalOptions="FillAndExpand"
        HorizontalOptions="FillAndExpand">
        <controls:CarouselViewControl.ItemsSource>
            <x:Array
                Type="{x:Type View}">
                <ScrollView>
                    <AbsoluteLayout
                        Padding="0"
                        Margin="0">
                        <Image
                            Source="login_icon.png"
                            AbsoluteLayout.LayoutBounds=".5, .0, .3, .3"
                            AbsoluteLayout.LayoutFlags="All" />
                        <StackLayout
                            Orientation="Vertical"
                            AbsoluteLayout.LayoutBounds=".5, .5, .9, .35"
                            AbsoluteLayout.LayoutFlags="All">
                            <Label
                                Text="Unisciti a Youni!"
                                FontSize="Large"
                                FontAttributes="Bold"
                                XAlign="Center" />
                            <Entry
                                x:Name="NameEntry"
                                VerticalOptions="FillAndExpand"
                                Placeholder="Nome" />
                            <Entry
                                x:Name="SurnameEntry"
                                VerticalOptions="FillAndExpand"
                                Placeholder="Cognome" />
                            <Entry
                                x:Name="NewEmailEntry"
                                VerticalOptions="FillAndExpand"
                                Placeholder="Email"
                                Keyboard="Email" />
                            <Entry
                                x:Name="NewPasswordEntry"
                                VerticalOptions="FillAndExpand"
                                Placeholder="Password"
                                IsPassword="true" />
                        </StackLayout>
                        <Button
                            x:Name="RegisterButton"
                            Clicked="Register_Handle_Clicked"
                            AbsoluteLayout.LayoutBounds=".5, .85, .3, .07"
                            AbsoluteLayout.LayoutFlags="All"
                            Text="Registrati"
                            TextColor="White"
                            BackgroundColor="#3A8FDA" />
                        <StackLayout
                            Orientation="Horizontal"
                            HorizontalOptions="Center"
                            AbsoluteLayout.LayoutBounds=".5, 1, 1, .1"
                            AbsoluteLayout.LayoutFlags="All">
                            <StackLayout.Spacing>
                                <OnPlatform
                                    x:TypeArguments="x:Double">
                                    <On
                                        Platform="Android"
                                        Value="-10" />
                                    <On
                                        Platform="iOS"
                                        Value="3" />
                                </OnPlatform>
                            </StackLayout.Spacing>
                            <Label
                                Text="Sei già registrato?"
                                FontSize="Small"
                                YAlign="Center"
                                XAlign="Center" />
                            <Button
                                x:Name="LoginSwitchButton"
                                Pressed="LoginSwitch_Handle_Pressed"
                                Released="LoginSwitch_Handle_Released"
                                Clicked="LoginSwitch_Handle_Clicked"
                                Text="Passa al login"
                                FontSize="Small"
                                TextColor="#45BFEE"
                                BackgroundColor="Transparent" />
                        </StackLayout>
                    </AbsoluteLayout>
                </ScrollView>
                <ScrollView>
                    <AbsoluteLayout
                        Padding="0"
                        Margin="0">
                        <Image
                            Source="login_icon.png"
                            AbsoluteLayout.LayoutBounds=".5, .215, .3, .3"
                            AbsoluteLayout.LayoutFlags="All" />
                        <StackLayout
                            Orientation="Vertical"
                            AbsoluteLayout.LayoutBounds=".5, .6, .9, .14"
                            AbsoluteLayout.LayoutFlags="All">
                            <Entry
                                x:Name="EmailEntry"
                                VerticalOptions="FillAndExpand"
                                Placeholder="Email"
                                Keyboard="Email" />
                            <Entry
                                x:Name="PasswordEntry"
                                VerticalOptions="FillAndExpand"
                                Placeholder="Password"
                                IsPassword="true" />
                        </StackLayout>
                        <Button
                            x:Name="LoginButton"
                            Clicked="Login_Handle_Clicked"
                            AbsoluteLayout.LayoutBounds=".5, .85, .3, .07"
                            AbsoluteLayout.LayoutFlags="All"
                            Text="Login"
                            TextColor="White"
                            BackgroundColor="#3A8FDA" />
                        <StackLayout
                            Orientation="Horizontal"
                            HorizontalOptions="Center"
                            AbsoluteLayout.LayoutBounds=".5, 1, 1, .1"
                            AbsoluteLayout.LayoutFlags="All">
                            <StackLayout.Spacing>
                                <OnPlatform
                                    x:TypeArguments="x:Double">
                                    <On
                                        Platform="Android"
                                        Value="-10" />
                                    <On
                                        Platform="iOS"
                                        Value="3" />
                                </OnPlatform>
                            </StackLayout.Spacing>
                            <Label
                                Text="Ancora senza account?"
                                FontSize="Small"
                                YAlign="Center"
                                XAlign="Center" />
                            <Button
                                x:Name="RegistrationSwitchButton"
                                Pressed="RegistrationSwitch_Handle_Pressed"
                                Released="RegistrationSwitch_Handle_Released"
                                Clicked="RegistrationSwitch_Handle_Clicked"
                                Text="Registrati"
                                FontSize="Small"
                                TextColor="#45BFEE"
                                BackgroundColor="Transparent" />
                        </StackLayout>
                    </AbsoluteLayout>
                </ScrollView>
            </x:Array>
        </controls:CarouselViewControl.ItemsSource>
    </controls:CarouselViewControl>
</ContentPage>

In the code-behind, I can handle the buttons Clicked events, but I can't access any of the views (entries, buttons, images etc...). Always throws System.NullReferenceException. Seems like all the views are null, which does not make sense.

Stack trace:

System.NullReferenceException: Object reference not set to an instance of an object
at Youni.PresentationPage+d__5.MoveNext () [0x00034] in /Users/Max/Documents/Xamarin/Youni/Youni/Youni/PresentationPage.xaml.cs:51
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.3.0.47/src/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:151
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__6_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.3.0.47/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1018
at UIKit.UIKitSynchronizationContext+c__AnonStorey0.<>m__0 () [0x00000] in /Users/builder/data/lanes/5520/51128b8c/source/xamarin-macios/src/UIKit/UIKitSynchronizationContext.cs:24
at Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Users/builder/data/lanes/5520/51128b8c/source/xamarin-macios/src/Foundation/NSAction.cs:163
at at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/data/lanes/5520/51128b8c/source/xamarin-macios/src/UIKit/UIApplication.cs:79
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/5520/51128b8c/source/xamarin-macios/src/UIKit/UIApplication.cs:63
at Youni.iOS.Application.Main (System.String[] args) [0x00001] in /Users/Max/Documents/Xamarin/Youni/Youni/iOS/Main.cs:17


Viewing all articles
Browse latest Browse all 81910

Trending Articles