Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blank screen on Xamarin

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()
        {
        }
    }
}
like image 347
tubefavorites.com Avatar asked Sep 06 '16 08:09

tubefavorites.com


2 Answers

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>
like image 125
Vitaliy Litvinov Avatar answered Oct 24 '22 22:10

Vitaliy Litvinov


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

like image 1
tubefavorites.com Avatar answered Oct 24 '22 21:10

tubefavorites.com