0

在一个应用程序中,我有两个ContentView控件,我试图在顶级ContentPage. 第一个,ScaffoldView包含一些我想在整个应用程序中拥有的布局元素:

<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             x:Class="App.ScaffoldView">
    <ContentView.Content>
        <Grid
            Margin="10,35,10,10"
            VerticalOptions="FillAndExpand">
            <Grid.RowDefinitions>...</Grid.RowDefinitions>
            <!-- Awesome header stuff -->
            <!-- I'd like the below to take given content -->
            <ContentView
                Grid.Row="..."
                Content="{Binding Content}" />
            <!-- Even more awesome footer stuff -->
        </Grid>
    </ContentView.Content>
</ContentView>

第二个,InputsView只有几对Label/Entry元素:

<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             x:Class="App.InputsView">
    <ContentView.Content>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Label Text="Label1"
                   FontSize="Medium"
                   VerticalTextAlignment="Center"
                   HorizontalTextAlignment="End" />
            <Entry Grid.Column="1"
                   Text="Input1"
                   VerticalOptions="Center" />
            <Label Grid.Row="1"
                   Text="Label2"
                   FontSize="Medium"
                   VerticalTextAlignment="Center"
                   HorizontalTextAlignment="End" />
            <Entry Grid.Row="1"
                   Grid.Column="1"
                   Text="Input2"
                   VerticalOptions="Center" />
            <Label Grid.Row="2"
                   Text="Label3"
                   FontSize="Medium"
                   VerticalTextAlignment="Center"
                   HorizontalTextAlignment="End" />
            <Entry Grid.Row="2"
                   Grid.Column="1"
                   Text="Input3"
                   VerticalOptions="Center" />
        </Grid>
    </ContentView.Content>
</ContentView>

最后,顶层ContentPage

<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:controls="clr-namespace:App"
             x:Class="App.MainPage">
    <controls:ScaffoldView>
        <controls:InputsView />
    </controls:ScaffoldView>
</ContentPage>

目前,所有显示的是InputsView. 我想这只是因为整个ContentMainPage占用了,而中定义ScaffoldView的整个被标签覆盖了。ContentScaffoldViewScaffold.xaml<controls:InputsView />

理想情况下,我希望有某种方式包含<controls:InputsView />在上面的开始和结束<controls:ScaffoldView>标签中,并将这个给定ScaffoldView的内容显示在Scaffold.xaml.

是否可以以这种方式嵌套/混合Content,或者我需要定义一个自定义属性,例如ChildContent

4

0 回答 0