gpt4 book ai didi

xaml - Xamarin 上的空白屏幕

转载 作者:行者123 更新时间:2023-12-04 12:20:04 25 4
gpt4 key购买 nike

我有一个 Xamarin 可移植项目。
我调试的 Xaml 页面完全空白,在 Android 和 IOS 页面上我都看不到任何组件。

我怎样才能解决这个问题?

注:它没有收到错误消息,页面正在打开,但我看不到任何内容。
问题发生在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);
}
}
}

应用程序.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()
{
}
}
}

最佳答案

您应该在 ctor 中调用 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>

关于xaml - Xamarin 上的空白屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39344199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com