【发布时间】:2021-01-31 19:28:48
【问题描述】:
所以,一切正常,当突然一个异常阻止我运行我的程序时,我可以看到我的代码的漂亮显示。我肯定做错了什么,但我不知道在哪里或做什么,因为我正在处理两个内容页面,一个工作正常,另一个内容页面几乎相同,除了显示更详细的信息。
错误:
错误 XFC0004 缺少“AoFStructures.StructureDepth”的默认构造函数`
我的允许导航的主页:
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:AoFStructures"
mc:Ignorable="d"
x:Class="AoFStructures.MainPage">
<NavigationPage Title="Structures">
<x:Arguments>
<local:StructureOverview/>
</x:Arguments>
</NavigationPage>
<NavigationPage Title="Structure info">
<x:Arguments>
<local:StructureDepth/>
</x:Arguments>
</NavigationPage>
</TabbedPage>
我的结构深度.xaml.cs
namespace AoFStructures
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class StructureDepth : ContentPage
{
Structure _selectedStructure;
StructureInfo _structured = null;
public StructureInfo ChosenStructure
{
get { return _structured; }
set { _structured = value; OnPropertyChanged("MyStructureName"); }
}
public StructureDepth(Structure structure)
{
BindingContext = this;
InitializeComponent();
_selectedStructure = structure;
}
private void ContentPage_Appearing(object sender, EventArgs e)
{
}
}
}
结构深度.xaml
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:AoFStructures"
Appearing="ContentPage_Appearing"
x:Class="AoFStructures.StructureDepth">
<ContentPage.Content>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<StackLayout>
<Label Grid.Column="0" Text="Name:"/>
<Label Grid.Column="1" Text="{Binding ChosenStructure.Name}"/>
<Label Grid.Column="0" Text="Age:"/>
<Label Grid.Column="1" Text="{Binding ChosenStructure.Age}"/>
<Label Grid.Column="0" Text="Cost:"/>
<Label Grid.Column="1" Text="{Binding ChosenStructure.Cost}"/>
<Label Grid.Column="0" Text="Build time:"/>
<Label Grid.Column="1" Text="{Binding ChosenStructure.Build_item}"/>
</StackLayout>
</Grid>
</ContentPage.Content>
</ContentPage>
【问题讨论】:
标签: c# xamarin.forms