【问题标题】:Content Page inside a Tabbed Page using XAML in xamarin.forms在 xamarin.forms 中使用 XAML 的选项卡式页面内的内容页面
【发布时间】:2017-04-18 20:40:44
【问题描述】:

我有一个 TabbedPage,有 3 个孩子。

public partial class FactoryDetailsTabs : TabbedPage
    {
        public FactoryDetailsTabs()
        {
            InitializeComponent();

            Children.Add(new FactoryDetailsTabs_DashboardTab());
            Children.Add(new FactoryDetailsTabs_AnalysisTab());
            Children.Add(new FactoryDetailsTabs_SettingsTab());          

        }
}

第三个标签包含设置页面。使用以下代码

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="LogicalSugarDemoApp.Pages.FactoryDetailsTabs_SettingsTab"
             xmlns:controls="clr-namespace:LogicalSugarDemoApp.NativeModels"            
             Title="Settings" Icon="settings">
    <RelativeLayout>
        <Frame x:Name="LanguageFrame" BackgroundColor="Pink">
            <RelativeLayout 
                RelativeLayout.XConstraint=
                     "{ConstraintExpression Type=RelativeToParent,                                                                                                      
                                            Property=Width,
                                            Factor=0.20}"
                 RelativeLayout.YConstraint=
                     "{ConstraintExpression Type=RelativeToParent,
                                            Property=Height,
                                            Factor=10.00}" 
                 RelativeLayout.WidthConstraint=
                     "{ConstraintExpression Type=RelativeToParent,
                                            Property=Width,
                                            Factor=0.40}"
                 RelativeLayout.HeightConstraint=
                     "{ConstraintExpression Type=RelativeToParent,
                                              Property=Height,
                                            Factor=0.05}">
                <Label x:Name="SelectLangLabel" 
                        Text="Select Language"
                        TextColor="Black"
                        BackgroundColor="Teal"
                        FontFamily="Arial"
                        FontSize="30"
                        FontAttributes="Bold"
                     RelativeLayout.XConstraint=
                         "{ConstraintExpression Type=RelativeToParent,                                                                                                      
                                            Property=Width,
                                            Factor=0.02}"
                     RelativeLayout.YConstraint=
                         "{ConstraintExpression Type=RelativeToParent,
                                                Property=Height,
                                                Factor=0.05}" 
                     RelativeLayout.WidthConstraint=
                         "{ConstraintExpression Type=RelativeToParent,
                                                Property=Width,
                                                Factor=0.70}"
                     RelativeLayout.HeightConstraint=
                         "{ConstraintExpression Type=RelativeToParent,
                                                  Property=Height,
                                                Factor=0.10}"/>
                <Picker x:Name="LanguagePicker" 
                        Title="English"
                        BackgroundColor="#e9e9e9"
                     RelativeLayout.XConstraint=
                         "{ConstraintExpression Type=RelativeToParent,                                                                                                      
                                            Property=Width,
                                            Factor=0.76}"
                     RelativeLayout.YConstraint=
                         "{ConstraintExpression Type=RelativeToParent,
                                                Property=Height,
                                                Factor=0.05}" 
                     RelativeLayout.WidthConstraint=
                         "{ConstraintExpression Type=RelativeToParent,
                                                Property=Width,
                                                Factor=0.23}"
                     RelativeLayout.HeightConstraint=
                         "{ConstraintExpression Type=RelativeToParent,
                                                  Property=Height,
                                                Factor=0.10}"/>
            </RelativeLayout>
        </Frame>
    </RelativeLayout>
    <controls:AdView HorizontalOptions="Center" VerticalOptions="EndAndExpand"/>


</ContentPage>

我在标签页内的第三页上没有得到任何输出。但是当我在 TabbedPage 之外的内容页面中执行此代码时,它可以工作。请帮忙。我需要它在 TabbedPage 中

【问题讨论】:

  • 你能分享一下你在两种不同场景中得到的截图吗,因为我在标签页内显示粉红色并带有一些青色线。

标签: xaml visual-studio-2015 xamarin.forms


【解决方案1】:

我认为您应该将RelativeLayout 添加到ContentPage.Content。类似的东西

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="LogicalSugarDemoApp.Pages.FactoryDetailsTabs_SettingsTab"
             xmlns:controls="clr-namespace:LogicalSugarDemoApp.NativeModels"            
             Title="Settings" Icon="settings">
  <ContentPage.Content>
    <RelativeLayout>
        <Frame x:Name="LanguageFrame" BackgroundColor="Pink">
            <RelativeLayout 
                RelativeLayout.XConstraint=
                     "{ConstraintExpression Type=RelativeToParent,                                                                                                      
                                            Property=Width,
                                            Factor=0.20}"
                 RelativeLayout.YConstraint=
                     "{ConstraintExpression Type=RelativeToParent,
                                            Property=Height,
                                            Factor=10.00}" 
                 RelativeLayout.WidthConstraint=
                     "{ConstraintExpression Type=RelativeToParent,
                                            Property=Width,
                                            Factor=0.40}"
                 RelativeLayout.HeightConstraint=
                     "{ConstraintExpression Type=RelativeToParent,
                                              Property=Height,
                                            Factor=0.05}">
                <Label x:Name="SelectLangLabel" 
                        Text="Select Language"
                        TextColor="Black"
                        BackgroundColor="Teal"
                        FontFamily="Arial"
                        FontSize="30"
                        FontAttributes="Bold"
                     RelativeLayout.XConstraint=
                         "{ConstraintExpression Type=RelativeToParent,                                                                                                      
                                            Property=Width,
                                            Factor=0.02}"
                     RelativeLayout.YConstraint=
                         "{ConstraintExpression Type=RelativeToParent,
                                                Property=Height,
                                                Factor=0.05}" 
                     RelativeLayout.WidthConstraint=
                         "{ConstraintExpression Type=RelativeToParent,
                                                Property=Width,
                                                Factor=0.70}"
                     RelativeLayout.HeightConstraint=
                         "{ConstraintExpression Type=RelativeToParent,
                                                  Property=Height,
                                                Factor=0.10}"/>
                <Picker x:Name="LanguagePicker" 
                        Title="English"
                        BackgroundColor="#e9e9e9"
                     RelativeLayout.XConstraint=
                         "{ConstraintExpression Type=RelativeToParent,                                                                                                      
                                            Property=Width,
                                            Factor=0.76}"
                     RelativeLayout.YConstraint=
                         "{ConstraintExpression Type=RelativeToParent,
                                                Property=Height,
                                                Factor=0.05}" 
                     RelativeLayout.WidthConstraint=
                         "{ConstraintExpression Type=RelativeToParent,
                                                Property=Width,
                                                Factor=0.23}"
                     RelativeLayout.HeightConstraint=
                         "{ConstraintExpression Type=RelativeToParent,
                                                  Property=Height,
                                                Factor=0.10}"/>
            </RelativeLayout>
        </Frame>
    </RelativeLayout>
    <controls:AdView HorizontalOptions="Center" VerticalOptions="EndAndExpand"/>

  </ContentPage.Content>
</ContentPage>

但不知道能不能解决问题

【讨论】:

  • 应用程序控制台是否有警告?
  • 在将代码添加到 后出现“序列不包含元素”的错误
  • 我已将您的代码复制并粘贴到表单中,我得到了这个结果dropbox.com/s/h5cuf4zovcmskik/…(我只删除了最后一行“AdView”)
  • 我已经解决了这个问题。那个 AdView 控件超出了 RelativeLayout,所以它没有给我输出,并且得到了错误,因为 "Sequence contains no element" 。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-30
相关资源
最近更新 更多