gpt4 book ai didi

c# - Xamarin Master 和 MasterDetailPage InvalidOperationException

转载 作者:太空宇宙 更新时间:2023-11-03 22:36:28 25 4
gpt4 key购买 nike

我不确定为什么会收到此错误我已经阅读了很多有关此错误的信息,听起来它与未设置 xaml 文件中的标题有关。我所有的页面都有标题集。错误来自 app.xaml.cs MainPage= new MainPage();

is there something else that can trigger this exeception?

System.InvalidOperationException: 在将 MasterDetailPage 添加到容器之前必须设置 Master 和 Detail

主页.xaml

<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:pages="clr-namespace:ReimbursementApp.Pages"
x:Class="ReimbursementApp.Pages.MainPage"
xmlns:telerikPrimitives="clr-namespace:Telerik.XamarinForms.Primitives;assembly=Telerik.XamarinForms.Primitives"
Title="Main">

<MasterDetailPage.Master>
<pages:MenuPage />
</MasterDetailPage.Master>

</MasterDetailPage>

菜单页面.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="ReimbursementApp.Pages.MenuPage"
xmlns:telerikPrimitives="clr-namespace:Telerik.XamarinForms.Primitives;assembly=Telerik.XamarinForms.Primitives"
xmlns:telerik="clr-namespace:Telerik.XamarinForms.DataControls;assembly=Telerik.XamarinForms.DataControls"
Title="Menu">
<!--<ContentPage.ToolbarItems>
<ToolbarItem Activated="OnToolbarButtonClick" Order="Primary" Priority="0" Icon="hamburgerButtonIcon"/>
</ContentPage.ToolbarItems>
<Grid>
<telerikPrimitives:RadSideDrawer x:Name="drawer" DrawerLength="250">
</telerikPrimitives:RadSideDrawer>
</Grid>-->

<StackLayout VerticalOptions="FillAndExpand">
<ListView x:Name="ListViewMenu"
HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Padding="10">
<Label Text="{Binding Title}" FontSize="20"/>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>

最佳答案

错误消息字面意思是出了什么问题:

Master and Detail must be set before adding MasterDetailPage to a container

您已经在 Master 属性中设置了一些内容,如下所示:

<MasterDetailPage.Master> 
<pages:MenuPage />
</MasterDetailPage.Master>

但您还应该设置 Detail 属性,如下所示:

<MasterDetailPage.Detail> 
<pages:MyMainPage />
</MasterDetailPage.Detail>

MasterDetailPage 只是一个容器,必须同时具有主控(通常是菜单)和详细信息(从菜单中选择的内容)以显示有用的内容。

关于c# - Xamarin Master 和 MasterDetailPage InvalidOperationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54908092/

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