【问题标题】:Xamarin - How can I call a TabbedPageXamarin - 我如何调用 TabbedPage
【发布时间】:2014-09-29 18:29:38
【问题描述】:

我目前正在学习 Xamarin 开发,看起来学习曲线相当长。

我有一个标签页类 (TabbedPageTest.cs),我继承自 TabbedPage。

现在我如何才能查看该页面。

假设我想使用表格视图中的单元格进行导航。

TableView tb = new TableView
                {
                    Intent = TableIntent.Menu,
                    Root = new TableRoot
                    {
                        new TableSection("Tabbed Page Test")
                        {
                            new TextCell
                            {
                              // What all codes can I add here to navigate or view TabbedPageTest.cs?
                            }
                        }
                    }
                 }

【问题讨论】:

    标签: xamarin.ios xamarin xamarin.forms


    【解决方案1】:

    //要在 PCL 中用于 Xamarin.Forms 的选项卡式页面演示代码

        TabbedPage tabs = new TabbedPage ();
    
        tabs.Children.Add(
            new NavigationPage (new MainPage () { Title = "Title for MainPage" }) {
                Title = "Tile for TabbedPage Tab1" // Add this title for your TabbedPage
            }
        );
    
        tabs.Children.Add(
            new NavigationPage (new FirstPage () { Title = "Title for FirstPage" }) {
                Title = "Tile for TabbedPage Tab2" // Add this title for your TabbedPage
            }
        );
        return  tabs;
    

    希望对你有帮助

    【讨论】:

      【解决方案2】:

      这是我在 Xamarin 表单中的标签页代码...

          <?xml version="1.0" encoding="UTF-8"?>
         <TabbedPage 
         xmlns="http://xamarin.com/schemas/2014/forms" 
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
         xmlns:me="clr-namespace:EvalUate;assembly=EvalUate"   
         x:Class="EvalUate.MainPage"
         Title="EvalUate">
          <TabbedPage.Children>
              <me:AppliancePage />
              <me:HelpPage />
              <me:LicensePage />
          </TabbedPage.Children>
         </TabbedPage>
      

      有了它,不需要代码,它会找到正确的页面。

      【讨论】:

      • 抱歉,我们没有使用 Xaml 代码。如何使用视图或推送方法调用它...谢谢
      【解决方案3】:

      您要求提供 C# 中的代码。给你...

      public partial class MainPage : TabbedPage    // Note inherits from TabbedPage
      {
          public MainPage ( )
          {
              this.Title = "Tabbed Page Demo";
              var appliancePage = new AppliancePage ( );
              var helpPage = new HelpPage ( );
              this.Children.Add( appliancePage );
              this.Children.Add( helpPage );
          }
      }
      

      以上内容在 MainPage.cs 中。 MainPage.xaml 看起来像这样:

      <?xml version="1.0" encoding="UTF-8"?>
      <TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"   <!-- note TabbedPage -->
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      x:Class="XamlToCSharpDemo.MainPage">
      </TabbedPage>
      

      请记住,每个子页面(例如,HelpPage)都必须有一个标题...

      <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      x:Class="XamlToCSharpDemo.HelpPage" Title="Help">   <!-- Note Title -->
        <ContentPage.Content>
          <Label Text="Help Page"/> 
        </ContentPage.Content>
      </ContentPage>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-03-21
        • 1970-01-01
        • 2019-03-20
        • 1970-01-01
        • 1970-01-01
        • 2020-06-13
        • 2022-01-08
        • 1970-01-01
        相关资源
        最近更新 更多