我无法调用MasterDetailForm的明细。代码正在运行,但不会显示。 我能怎么做? “ PageLog:单击按钮打开PageReg” 我对Hamburgermenu没问题。问题是我无法从其他页面访问。
MainPage.xml.cs
public partial class MainPage : MasterDetailPage
{
... // Main functions...
public void ExportMDP() // Open new content
{
Detail = new NavigationPage((Page)Activator.CreateInstance(typeof(PageReg)));
IsPresented = false;
}
}
PageLog.xml.cs
public partial class PageLog : ContentPage
{
...
void RegClick(object sender, EventArgs args) // Button Click
{
var x = new project.MainPage();
x.ExportMDP();
}
}
答案 0 :(得分:1)
根据您的描述,如果要从其他内容页面调用masterdetailPage,则可以使用Navigation.PushModalAsync()方法执行此操作。
Navigation.PushModalAsync(new MastDetailPage());
您可以在MasterDetailPage中导航详细信息页面。
这是MastDetailPage:
<MasterDetailPage.Master>
<local:MasterPage x:Name="masterPage" />
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage>
<x:Arguments>
<local:ContactsPage />
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
public partial class MainPage : MasterDetailPage
{
public MainPage()
{
InitializeComponent();
masterPage.listView.ItemSelected += OnItemSelected;
if (Device.RuntimePlatform == Device.UWP)
{
MasterBehavior = MasterBehavior.Popover;
}
}
void OnItemSelected(object sender, SelectedItemChangedEventArgs e)
{
var item = e.SelectedItem as MasterPageItem;
if (item != null)
{
Detail = new NavigationPage((Page)Activator.CreateInstance(item.TargetType));
masterPage.listView.SelectedItem = null;
IsPresented = false;
}
}
}
这是MastPage:
<StackLayout>
<ListView x:Name="listView" x:FieldModifier="public">
<ListView.ItemsSource>
<x:Array Type="{x:Type local:MasterPageItem}">
<local:MasterPageItem Title="Contacts" IconSource="contacts.png" TargetType="{x:Type local:ContactsPage}" />
<local:MasterPageItem Title="TodoList" IconSource="todo.png" TargetType="{x:Type local:TodoListPage}" />
<local:MasterPageItem Title="Reminders" IconSource="reminders.png" TargetType="{x:Type local:ReminderPage}" />
</x:Array>
</ListView.ItemsSource>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Padding="5,10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30"/>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Source="{Binding IconSource}" />
<Label Grid.Column="1" Text="{Binding Title}" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>