2016-12-25 34 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

我會盡力讓你知道。我沒看到代碼。命名規則讓我略微放棄了一點。 –