【问题标题】:Coding a Navigation Drawer Menu (Slider Menu). (Master Page Detail)编码导航抽屉菜单(滑块菜单)。 (母版页详细信息)
【发布时间】:2017-01-28 15:18:06
【问题描述】:

尝试构建一个滑块菜单我正在使用来自官方 Xamarin 的这个文档。 MasterPageDetail

很奇怪,它不起作用。 VS2015 intellense 认出了我 MasterDetailPage(我的类继承自它),但是当我尝试启动应用程序时,出现下一个错误:

命名空间“Xamarin.Forms”中不存在类型或命名空间名称“MasterPageDetail”(您是否缺少程序集引用?)

会发生什么?你知道任何简单的工作演示吗? 我正在使用这个问题作为参考,但我没有得到它的工作... Slider

一些答案​​使用 MasterPageDetail,另一个在应用程序(类)中实现了解决方案,我需要在 ContentPage 中完成

谢谢小伙伴们。

已编辑:我正在使用 Xamarin.Forms 并导入了它,但我没有任何这样的类 (MasterPageDetail)... 很奇怪,这听起来很愚蠢,但我看不到它。

【问题讨论】:

    标签: c# xaml xamarin xamarin.forms


    【解决方案1】:

    MasterDetailPage 是来自 Xamarin.Forms 的类,如果您有同名的类,则可能是冲突。

    这里有一些有用的链接:

    https://developer.xamarin.com/guides/xamarin-forms/user-interface/navigation/master-detail-page/

    https://developer.xamarin.com/api/type/Xamarin.Forms.MasterDetailPage/

    您也可以从我的 Github 下载我的示例:

    https://github.com/15mgm15/XamarinForms-MasterDetailPage-Recipe

    【讨论】:

    • 嗨@Mario Galván。不,我正在使用 Xamarin.Forms 并导入了它,但我没有任何这样的类......很奇怪,这听起来很愚蠢,但我看不到它。
    【解决方案2】:
    • 有一种使用 XAML 创建MasterDetailPage 的简单方法,首先您需要创建一个包含MasterDetailPage 和一个包含SecondPage 的页面,其中包含DetailPage,方法是为此,您需要将此页面的层次结构更改为MasterDetailPage,最后在MasterDetailPage 中加载SecondPage

    • 在您的项目中创建一个新页面 - MenuPage 并将页面类型 ContentPage 更改为 MasterDetailPage

      <MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
           BackgroundColor="White"
           xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
           x:Class="YourProject.MenuPage">
      </MasterDetailPage>
      
    • 然后转到您的MenuPage.cs 并将层次结构也更改为 MasterDetailPage。

      public partial class MenuPage : MasterDetailPage
      {
         public ChatPage()
         {
             InitializeComponent();
         }
      }
      
    • 返回您的 XAML 页面 - MenuPage 并添加以下内容:

         <MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
           xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
           x:Class="YourProjectName.MenuPage">
      
      <MasterDetailPage.Master>
        <ContentPage  Title="Menu">
         <StackLayout Orientation="Vertical">
            <!--Here goes your Menu Items-->
           <Button Text="MyFirstButton"/>
           <Button Text="MySecondButton"/>
           <Button Text="MyThirdButton"/>
         </StackLayout>
       </ContentPage>
      </MasterDetailPage.Master>
      <MasterDetailPage.Detail>
        <local:SecondPage/>
      </MasterDetailPage.Detail>
      </MasterDetailPage>
      
    • 最后你需要添加对DetailPage的引用

         <MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
           xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
           x:Class="YourProjectName.MenuPage"
           <!-- Add this line to refer your DetailPage, `SecondPage`-->
           <!-- put your namespace and repeat in assembly -->
           xmlns:local="clr-namespace:YourProjectName;assembly=YourProjectName">
         </MasterDetailPage>
      

    希望对你有帮助!

    【讨论】:

      【解决方案3】:

      我明白了。

      最后,我清理了所有项目并使用下一个示例从零开始编写代码(仅添加 MasterPageItem.cs,小菜一碟):

      Working MasterDetailDemo

      我自己改进了演示,创建了一个 Master Page Detail,其中 Master 的项目绑定特定的通用页面,它将填充其自己的属性,其依赖 id 传递给页面的构造函数。

      Github Slider Menu improved demo

      希望对您有所帮助...

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-05-27
        • 2015-09-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多