Xamarin上的空白屏幕

问题描述:

我有一个Xamarin便携式项目。
我调试的Xaml页面是完全空白的,我无法在Android和IOS页面上看到任何组件。
Xamarin上的空白屏幕

我该如何解决这个问题?

注意:它没有得到错误消息,页面打开,我看不到任何东西。
问题发生在this error之后。当我修复它时,我调试的页面变成空的,
虽然它们在InitializeComponent错误之前工作。

任何帮助将不胜感激。

这是我的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> 

这是我的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() 
     { 
     } 
    } 
} 
+0

为什么要投票? –

+1

您不会发布任何示例代码,也不会显示错误消息,并且无需付出任何努力。我们没有魔镜,我们可以看到您所做的一切,因此您的部分调查和信息不仅得到了赞赏,而且如果您想要任何好的答案,也是必要的。 –

+0

Okey我更新了我的问题。 –

,你应该调用的InitializeComponent()在构造函数。 否则UI元素将不会从xaml文件初始化。

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); 
     } 
    } 
} 

好吧, 看起来有在XAML文件中的错误

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

没有棕褐色,尝试从this table

这对我的作品

<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> 
选择的东西
+0

Okey已添加,但它仍然显示为空白屏幕。 –

+0

您能否展示您的App.cs和App.xaml –

+0

Okey已更新并添加App.cs –

事实上,似乎在初始化公司mponent线是需要的。