C# Xamarin MasterDetailPage按钮
我如何通过Homepage.xaml.cs和Homepage.xaml中的可点击按钮来引用母版详细信息页面(菜单导航) 我希望每当我单击“菜单”按钮时,侧菜单都会出现。(见下文) 我在Homepage.xaml.cs中的clicked button事件处理程序中尝试了MasterDetail.isPresentedProperty,但无法找到它 请帮忙 MenuNavigation.xaml:C# Xamarin MasterDetailPage按钮,c#,xaml,xamarin,xamarin.forms,master-detail,C#,Xaml,Xamarin,Xamarin.forms,Master Detail,我如何通过Homepage.xaml.cs和Homepage.xaml中的可点击按钮来引用母版详细信息页面(菜单导航) 我希望每当我单击“菜单”按钮时,侧菜单都会出现。(见下文) 我在Homepage.xaml.cs中的clicked button事件处理程序中尝试了MasterDetail.isPresentedProperty,但无法找到它 请帮忙 MenuNavigation.xaml: <MasterDetailPage xmlns="http://xamarin.com/sch
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="App2.MenuNavigation"
xmlns:local="clr-namespace:App2">
<!--this is the Menu Hamburger sidebar -->
<MasterDetailPage.Master>
<ContentPage Title="Menu" Padding="20" BackgroundColor="#4B1388" >
<StackLayout Orientation="Vertical">
<Label Text="Menu" TextColor="White" FontSize="Large" FontAttributes="Bold" HorizontalOptions="Center"/>
<Button Text="Home"
TextColor="White" BackgroundColor="#4B1388"
Clicked="Button_Clicked_Home"/> <!-- event handler points to MenuNavigation C# file when button is clicked-->
<Button Text="About"
TextColor="White" BackgroundColor="#4B1388"
Clicked="Button_Clicked_About"/>
<Button Text="Help"
TextColor="White" BackgroundColor="#4B1388"
Clicked="Button_Clicked_Help"/>
</StackLayout>
</ContentPage>
</MasterDetailPage.Master>
<!--links to the detail pages from the hamburger sidebar -->
<MasterDetailPage.Detail>
</MasterDetailPage.Detail>
}
Homepage.xaml:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="App2.Homepage"
Title="Homepage">
<Button Text="Menu" Clicked="MasterDetailButton_Pressed"/>
</ContentPage>
您应该获得MasterDetailPage的引用,并更改引用的IsPresented属性。由于MasterDetailPage必须是应用程序的根目录,类似这样的操作应该有效:
(app.Current.MainPage作为MasterDetailPage)。IsPresented=true代码>
希望有帮助!:)
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="App2.Homepage"
Title="Homepage">
<Button Text="Menu" Clicked="MasterDetailButton_Pressed"/>
</ContentPage>
namespace App2
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Homepage : ContentPage
{
public Homepage()
{
InitializeComponent();
VideoListView.ItemsSource = Videos; //allows for binding
}
private void MasterDetailButton_Pressed(object sender, EventArgs e)
{
MasterDetailPage.IsPresentedProperty.Equals(true);
//open the master detail page when button is clicked.
//MasterDetailPage.IsPresentedProperty.Equals(true);
//MenuNavigation.IsPresentedProperty.Equals(true);
}
}
}