NicoRiff
NicoRiff

Reputation: 4883

Blank page when ContentView is not visible

I´m having a problem trying to display a loading page on Xamarin Forms. The loading page displays just right but when I set ContentView.IsVisible = false the StackLayout that is supposed to be viewed is not visible. Can anyone help me with this?. This is the XAML code and the code behind:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MobileAccessControl.Views.ConfigurarLectora">
    <ContentPage.ToolbarItems>
        <ToolbarItem Text="Guardar" Clicked="ToolbarItem_Clicked" />
    </ContentPage.ToolbarItems>
    <ScrollView>
        <StackLayout x:Name="slPrincipal" VerticalOptions="Center" HorizontalOptions="Center">
            <StackLayout Padding="20,20,20,20" VerticalOptions="Center" HorizontalOptions="Center">
                <Image Source="danger.jpg" HeightRequest="50" WidthRequest="50"/>
            </StackLayout>
            <StackLayout VerticalOptions="Center" HorizontalOptions="Center">
                <Picker x:Name="pckPanel" 
                        ItemsSource="{Binding ListaPaneles}" 
                        ItemDisplayBinding="{Binding Name}" 
                        Title="Panel" 
                        SelectedIndexChanged="pckPanel_SelectedIndexChanged"
                        WidthRequest="360"/>
                <Picker x:Name="pckLectoraEntrada" 
                        ItemsSource="{Binding ListaLectoras}" 
                        ItemDisplayBinding="{Binding Name}" 
                        Title="Lectora de Entrada" 
                        SelectedIndexChanged="pckLectora_SelectedIndexChanged" 
                        WidthRequest="360"/>
                <Picker x:Name="pckLectoraSalida" 
                        ItemsSource="{Binding ListaLectoras}" 
                        ItemDisplayBinding="{Binding Name}" 
                        Title="Lectora de Salida" 
                        SelectedIndexChanged="pckLectoraSalida_SelectedIndexChanged" />
            </StackLayout>
        </StackLayout>
        <ContentView x:Name="LoadingOverlay" AbsoluteLayout.LayoutBounds="0, 0, 1, 1"  AbsoluteLayout.LayoutFlags="All" IsVisible="True" BackgroundColor="#C0808080" Padding="10, 0">
            <ActivityIndicator  WidthRequest="110" HeightRequest="70" IsRunning="True" IsVisible="True" Color="DarkGray" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>
        </ContentView>
    </ScrollView>
</ContentPage>

CS:

    protected async override void OnAppearing()
    {
        if (await _conf.GetListaPaneles())
        {
            LoadingOverlay.IsVisible = false;
        }

        base.OnAppearing();
    }

Upvotes: 1

Views: 351

Answers (1)

NicoRiff
NicoRiff

Reputation: 4883

My bad. It seems that what I´m trying to accomplish is not possible if the ContentView is not inside a AbsoluteLayout. I fixed the situation by doing the following:

<ScrollView>
        <AbsoluteLayout>
            <StackLayout x:Name="slPrincipal" VerticalOptions="Center" HorizontalOptions="Center">
                <StackLayout Padding="20,20,20,20" VerticalOptions="Center" HorizontalOptions="Center">
                    <Image Source="danger.jpg" HeightRequest="50" WidthRequest="50"/>
                    <Label Text="Ingrese los datos del panel y lectora asociados a la tablet en Lenel OnGuard. Se deberá elegir un panel virtual exclusivo para Tablets. IMPORTANTE: No seleccione un panel real con lectoras en linea. Se pueden generar problemas en la base de datos."/>
                </StackLayout>
                <StackLayout VerticalOptions="Center" HorizontalOptions="Center">
                    <Picker x:Name="pckPanel" 
                            ItemsSource="{Binding ListaPaneles}" 
                            ItemDisplayBinding="{Binding Name}" 
                            Title="Panel" 
                            SelectedIndexChanged="pckPanel_SelectedIndexChanged"
                            WidthRequest="360"/>
                    <Picker x:Name="pckLectoraEntrada" 
                            ItemsSource="{Binding ListaLectoras}" 
                            ItemDisplayBinding="{Binding Name}" 
                            Title="Lectora de Entrada" 
                            SelectedIndexChanged="pckLectora_SelectedIndexChanged" 
                            WidthRequest="360"/>
                    <Picker x:Name="pckLectoraSalida" 
                            ItemsSource="{Binding ListaLectoras}" 
                            ItemDisplayBinding="{Binding Name}" 
                            Title="Lectora de Salida" 
                            SelectedIndexChanged="pckLectoraSalida_SelectedIndexChanged" />
                </StackLayout>
            </StackLayout>
            <ContentView x:Name="LoadingOverlay" AbsoluteLayout.LayoutBounds="0, 0, 1, 1"  AbsoluteLayout.LayoutFlags="All" IsVisible="True" BackgroundColor="#C0808080" Padding="10, 0">
                <ActivityIndicator  WidthRequest="110" HeightRequest="70" IsRunning="True" IsVisible="True" Color="DarkGray" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>
            </ContentView>
        </AbsoluteLayout>
    </ScrollView>

Upvotes: 1

Related Questions