2016-12-25 46 views
-1

查看所有问题和论坛后,我仍无法使用汉堡图标获取我的主详细信息页面。如果我使用这个主细节页作为应用程序启动,那么我看到功能按预期工作。请看下面的代码无法获得基本的汉堡包详细信息视图

DashBoadCreator.xaml `

<MasterDetailPage.Master> 

</MasterDetailPage.Master> 

<MasterDetailPage.Detail> 

    </x:Arguments> 
</NavigationPage> 
</MasterDetailPage.Detail> 
` 

`public partial class DashBoadCreator : MasterDetailPage 
{ 
DashboardMaster master; 
DashboardDetail1 detil; 
public DashBoadCreator() 
{ 
InitializeComponent(); 
master = new DashboardMaster(); 
detil = new DashboardDetail1(); 

     Master = master; 
     Master.Title = "this is a title"; 
     Master.Icon = "icon.png"; 
     Detail = new NavigationPage(detil); 

    } 

    // Event for Menu Item selection, here we are going to handle navigation based 
    // on user selection in menu ListView 

}` 
DashboadMaster.xaml 
` 

<!-- 
     This StackLayout you can use for other 
     data that you want to have in your menu drawer 

    <StackLayout BackgroundColor="#e74c3c" 
       HeightRequest="75"> 

     <Label Text="Some Text title" 
      FontSize="20" 
      VerticalOptions="CenterAndExpand" 
      TextColor="White" 
      HorizontalOptions="Center"/> 
    </StackLayout>   --> 

<ListView x:Name="navigationDrawerList" 
      RowHeight="60" 
      SeparatorVisibility="None" 
      BackgroundColor="#e8e8e8" 
      ItemSelected="OnMenuItemSelected"> 

    <ListView.ItemTemplate> 
    <DataTemplate> 
     <ViewCell> 

     <!-- Main design for our menu items --> 
     <StackLayout VerticalOptions="FillAndExpand" 
        Orientation="Horizontal" 
        Padding="20,10,0,10" 
        Spacing="20"> 

      <Image Source="{Binding Icon}" 
       WidthRequest="40" 
       HeightRequest="40" 
       VerticalOptions="Center" /> 

      <Label Text="{Binding Title}" 
       FontSize="Medium" 
       VerticalOptions="Center" 
       TextColor="Black"/> 
     </StackLayout> 
     </ViewCell> 
    </DataTemplate> 
    </ListView.ItemTemplate> 
</ListView> 
` 

'公共部分类DashboardMaster:ContentPage {

public List<MasterPageItem> menuList { get; set; } 

public DashboardMaster() 
{ 
    Title = "samples"; 
    InitializeComponent(); 

    menuList = new List<MasterPageItem>(); 

    // Creating our pages for menu navigation 
    // Here you can define title for item, 
    // icon on the left side, and page that you want to open after selection 
    var page1 = new MasterPageItem() { Title = "Item 1", Icon = "itemIcon1.png", TargetType = typeof(DashboardDetail1) }; 
    var page2 = new MasterPageItem() { Title = "Item 2", Icon = "itemIcon2.png", TargetType = typeof(DashboardDetail1) }; 
    var page3 = new MasterPageItem() { Title = "Item 3", Icon = "itemIcon3.png", TargetType = typeof(DashboardDetail1) }; 
    var page4 = new MasterPageItem() { Title = "Item 4", Icon = "itemIcon4.png", TargetType = typeof(DashboardDetail1) }; 
    var page5 = new MasterPageItem() { Title = "Item 5", Icon = "itemIcon5.png", TargetType = typeof(DashboardDetail1) }; 
    var page6 = new MasterPageItem() { Title = "Item 6", Icon = "itemIcon6.png", TargetType = typeof(DashboardDetail1) }; 
    var page7 = new MasterPageItem() { Title = "Item 7", Icon = "itemIcon7.png", TargetType = typeof(DashboardDetail1) }; 
    var page8 = new MasterPageItem() { Title = "Item 8", Icon = "itemIcon8.png", TargetType = typeof(DashboardDetail1) }; 
    var page9 = new MasterPageItem() { Title = "Item 9", Icon = "itemIcon9.png", TargetType = typeof(DashboardDetail1) }; 

    // Adding menu items to menuList 
    menuList.Add(page1); 
    menuList.Add(page2); 
    menuList.Add(page3); 
    menuList.Add(page4); 
    menuList.Add(page5); 
    menuList.Add(page6); 
    menuList.Add(page7); 
    menuList.Add(page8); 
    menuList.Add(page9); 

    // Setting our list to be ItemSource for ListView in MainPage.xaml 
    navigationDrawerList.ItemsSource = menuList; 
    //Application.Current.MainPage = new DashboardMaster(); 
    // NavigationPage.SetHasNavigationBar(this, false); 

} 
private void OnMenuItemSelected(object sender, SelectedItemChangedEventArgs e) 
{ 
    DashBoadCreator creator = new DashBoadCreator(); 

    var item = (MasterPageItem)e.SelectedItem; 
    Type page = item.TargetType; 

    creator.Detail = new NavigationPage((Page)Activator.CreateInstance(page)); 
    creator.IsPresented = false; 
} 

}为

<ListView.ItemTemplate> 


      <Image Source="{Binding Icon}" 
        WidthRequest="40" 
        HeightRequest="40" 
        VerticalOptions="Center" /> 

      <Label Text="{Binding Title}" 
       FontSize="Medium" 
       VerticalOptions="Center" 
       TextColor="Black"/> 
     <!-- <Label Text="{Binding Description}" 
       FontSize="Small" 
       VerticalOptions="End"/>--> 
      <StackLayout VerticalOptions="End" HorizontalOptions="End"> 
      <Button Text="Apply" FontSize="10" TextColor="Green" BorderWidth="1" HorizontalOptions="End" /> 
      </StackLayout> 
     </StackLayout> 

     </ViewCell> 
    </DataTemplate> 
    </ListView.ItemTemplate> 

</ListView> 

回答

0

一些调查后,我来到accorss讨论

Missing menu button on MasterDetailPage when assigning App.MainPage

使用这些发现我改变了我的app.xaml.cs如下

MainPage = new NavigationPage(new MenuPage()); 
MasterDetailTest.App.Current.MainPage.Navigation.PushAsync(new MainPage()); 

现在的母版页始终是根页面和汉堡包菜单按预期工作。对于有这个问题的其他人希望这可以帮助你以某种方式

1

集图标母版页看到hambu rger图标

示例代码:

public masterpage() 
{ 
    Icon = "hamburger.png"; 
} 
+0

上面的代码不适用于我。我试过了。 –

+0

当您将MasterDetailPage作为App.Xaml.cs中的根页面时,所有内容都按预期工作。在我的情况下,我需要用户根据操作进行登录/注册,然后使用以下代码导航到MasterDetail页面: Application.Current.MainPage = new NavigationPage(new MenuPage()); Navigation.PopToRootAsync(true); 这次汉堡菜单消失了。 现在要补充一点,如果你改变你的设备方向(在模拟器上改变它,并尝试在Android手机上自动旋转),它神奇地出现!!!!!!!!!我该如何解决这个问题? –

+0

我必须在位于主页面的内容布局上设置图标。我也为我的详细信息页面使用导航页面。 – mac10688

0

我编写了以下几型动物TUTOS一个working's演示,并让他们的最重要的部分。所以,至少对我而言,这是一个我可以获得的简单演示。

检查此链接。

My github working demo

凡Intervection是随机的详细页面(通过参数的构造函数)。

让我知道你有任何疑问。

干杯队友。圣诞节快乐。

+0

我正在处理Xamain表单应用程序,所以也许你的代码不会帮助我。同时我有一个解决方案,我想。我会尝试一下并发布答案。 –

+0

我编码为xamarin形式。在所有平台中...... –

+0

我会尽力让你知道。我没看到代码。命名规则让我略微放弃了一点。 –

相关问题