繁体   English   中英

在xamarin.forms中使用XAML的选项卡式页面内的内容页面

[英]Content Page inside a Tabbed Page using XAML in xamarin.forms

我有一个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>

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

我认为您应该将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>

但我不知道它是否可以解决问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM