Blank screen on Xamarin
Asked Answered
J

2

5

I have a Xamarin portable project.
The Xaml pages I debug are totally blank and I cannot see any components on the pages on both Android and IOS.

How can I fix this?

Note: It gets no error messages, the pages are opening and I cannot see anything on them.
The problem occured after this error. When I fixed it the pages I debug become opening empty,
although they were working before InitializeComponent error.

Any help would be greatly appreciated.

This is my xaml :

<?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="AcikAkademi3.Layoutlar.GridOrnek3">

<Grid>
  <Grid.RowDefinitions>  
    <RowDefinition Height="*"></RowDefinition>
    <RowDefinition Height="*"></RowDefinition>
  </Grid.RowDefinitions>

  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="*"></ColumnDefinition>
    <ColumnDefinition Width="*"></ColumnDefinition>
    <ColumnDefinition Width="Auto"></ColumnDefinition>
  </Grid.ColumnDefinitions>

  <Label BackgroundColor="Red" Text="0,0" Grid.Column="0" Grid.Row="0">
  </Label>
  <Label BackgroundColor="Blue" Text="1,0" Grid.Column="1" Grid.Row="0">
  </Label>
  <Label BackgroundColor="Yellow" Text="Açık Akademi" Grid.Column="2" Grid.Row="0"></Label>

  <Label BackgroundColor="White" Text="0,1" Grid.Column="0" Grid.Row="1">
  </Label>
  <Label BackgroundColor="Silver" Text="1,1" Grid.Column="1" Grid.Row="1">
  </Label>
  <Label BackgroundColor="Lime" Text="2,1" Grid.Column="2" Grid.Row="1">
  </Label>

</Grid>
</ContentPage>

This is my cs :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace AcikAkademi3.Layoutlar
{
    public partial class GridOrnek3 : ContentPage
    {
        public GridOrnek3()
        {
            Padding = new Thickness(0, 20, 0, 0);
        }
    }
}

App.cs :

using AcikAkademi3.Layoutlar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xamarin.Forms;

namespace AcikAkademi3
{
    public class App : Application
    {
        public App()
        {
            MainPage = new GridOrnek3();
        }

        protected override void OnStart()
        {
        }

        protected override void OnSleep()
        {
        }

        protected override void OnResume()
        {
        }
    }
}
Jhvh answered 6/9, 2016 at 8:30 Comment(5)
Why down vote ?Jhvh
You do not post any sample code, no error messages and show no effort on your part. We have no magic mirror in which we can see everything you're doing so some investigation and information from your part is not only appreciated, but also necessary if you want any good answers.Torritorricelli
Okey I have updated my question.Jhvh
Please check again @Gerald VersluisJhvh
Anybody having the same problem ?Jhvh
T
8

You should call InitializeComponent() in ctor. Otherwise UI elements will not init from xaml file.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace AcikAkademi3.Layoutlar
{
    public partial class GridOrnek3 : ContentPage
    {
        public GridOrnek3()
        {
            InitializeComponent();
            Padding = new Thickness(0, 20, 0, 0);
        }
    }
}

Okay, Looks like there is a mistake in xaml file

<Label BackgroundColor="Brown" Text="0,1" Grid.Column="0" Grid.Row="1">
  </Label>

There is no Brown color, try to chose something from this table

This works for me

<Grid>
  <Grid.RowDefinitions>  
    <RowDefinition Height="*"/>
    <RowDefinition Height="*"/>
  </Grid.RowDefinitions>

  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="*"/>
    <ColumnDefinition Width="*"/>
    <ColumnDefinition Width="Auto"/>
  </Grid.ColumnDefinitions>

  <Label    Grid.Column="0" 
            Grid.Row="0"
            BackgroundColor="Red" 
            Text="0,0" />

  <Label    Grid.Column="1" 
            Grid.Row="0"
            BackgroundColor="Blue" 
            Text="1,0" />

  <Label    Grid.Column="2" 
            Grid.Row="0"
            BackgroundColor="Yellow" 
            Text="Açık Akademi"/>

  <Label    Grid.Column="0" 
            Grid.Row="1"
            BackgroundColor="Olive" 
            Text="0,1" />

  <Label    Grid.Column="1" 
            Grid.Row="1"
            BackgroundColor="Silver" 
            Text="1,1" />

  <Label    Grid.Column="2" 
            Grid.Row="1"
            BackgroundColor="Lime" 
            Text="2,1" />

</Grid>
Torres answered 6/9, 2016 at 13:13 Comment(3)
Okey have added but it still gets a blank screen.Jhvh
Yes you are right, I have corrected it and removed that color but my page is still blank when I runJhvh
Please see my note that I added below the question.Jhvh
J
1

In fact, it seems that upon the InitializeComponent line is needed.

Jhvh answered 8/9, 2016 at 13:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.