【问题标题】:How to Implement splitview in already present xamarin application?如何在已经存在的 xamarin 应用程序中实现拆分视图?
【发布时间】:2019-11-12 20:41:08
【问题描述】:

我有一个 Xamarin 应用程序,在开发时我们只关注 iphone 的外观。现在我们要在我们的应用程序中为某个页面实现 SplitView。

我已按照以下链接中的步骤进行操作:

https://devblogs.microsoft.com/xamarin/bringing-xamarin-forms-apps-to-tablets/

但它给出了运行时错误:

System.InvalidOperationException:必须在 Master 上设置 Title 属性 页面

我已经在 searchTabletpage.cs 文件中的链接中设置了标题。

public SearchTabletPage()
        {
            Title = "Details";
            this.MasterBehavior = MasterBehavior.Default;

            Master = new SearchPage(true);
            Detail = new ContentPage()
            {
                Content = new StackLayout
                {
                    VerticalOptions = LayoutOptions.Center,
                    HorizontalOptions = LayoutOptions.Center,

                    Children = {
                        new Label { Text = "Select a Record", FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)) }
                    }

                }

            };

            ((SearchPage)Master).ItemSelected = (searchDetail) =>
            {

                BusinessDetailPage businessDetail = new BusinessDetailPage(searchDetail.InfogroupId,searchDetail.Distance,searchDetail.FullAddress,searchDetail.Phone);
                Detail = businessDetail;
                if (Device.RuntimePlatform != Device.UWP)
                {
                    IsPresented = false;
                }
            };

            IsPresented = true;
        }
    }

请帮助我。 提前致谢。

【问题讨论】:

  • 不,我没有创建 masterDetail 页面。我只是创建空类,我只是添加上面显示的代码。 @G.hakim
  • 如果您有 Xamarin Forms 4.0 及更高版本,则使用 MasterDetailPage 或 Shell 实现 ios 的拆分视图
  • 我有专为 iphone 设计的应用程序,我只需要添加新页面,让它看起来像 ipad 中的 splitview 而已。你能为此提出任何新的解决方案吗?@G.hakim
  • 这正是你完成后它会做的事情,多个页面是你试图想出的同一个拆分视图,最好在确定它不是之前尝试一下你想要什么!

标签: xamarin xamarin.forms


【解决方案1】:

正如错误所说,您需要为 Master 页面设置标题。

Master = new SearchPage(true)
{
  Title = "Search Page"
};

【讨论】:

  • 我尝试了上述解决方案,但现在它抛出异常:Object reference not set to an instance of an object in Main.cs file of xamarin.ios Project.
  • 已编辑,答案,它不应该是空字符串,如果它仍然抛出异常,它主要与MasterDetail页面无关
  • 仍然抛出异常,您能否建议任何其他方法来实现 ipad 拆分视图设计。注意:我已经有适用于 iphone 的应用程序
  • 我假设您的 SearchPage 出现异常,您可以只保留两个内容页面作为主页面和详细页面,有助于解决问题
【解决方案2】:

您学习的教程是使用Master-Detailed Page,它是通过代码实现的。

在此处查看官方示例:https://github.com/xamarin/xamarin-forms-samples/tree/master/Navigation/MasterDetailPage/MasterDetailPageNavigation/CS

【讨论】:

    猜你喜欢
    • 2018-03-21
    • 1970-01-01
    • 2016-02-25
    • 1970-01-01
    • 2020-11-01
    • 1970-01-01
    • 2018-03-12
    • 2023-03-19
    • 1970-01-01
    相关资源
    最近更新 更多