0

我有一個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我更新了我的問題。 –

回答

2

,你應該調用的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 –

0

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