如何在StackLayout中交替标签和自定义视图?

时间:2014-09-17 18:46:17

标签: xamarin xamarin.forms

我正在尝试为组编辑页面创建一个布局,其中包含3个自定义视图和每个视图的标签:

<?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:vm="clr-namespace:...;assembly=..."
             xmlns:view="clr-namespace:...;assembly=..."
             x:Class="..."
             Title="Configure Group">
  <ScrollView>
    <StackLayout Padding="20">
      <Label Text="Person 1" Font="Large"/>      
      <view:EditPersonView/>
      <Label Text="Person 2" Font="Large"/>
      <view:EditPersonView/>
      <Label Text="Person 3" Font="Large"/>
      <view:EditPersonView/>
    </StackLayout>
  </ScrollView>
</ContentPage>

EditPersonView.cs

<?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:vm="clr-namespace:...;assembly=..."
                   x:Class="...EditPersonView">
    <ContentView.BindingContext>
        <vm:PersonViewModel/>
    </ContentView.BindingContext>
    <StackLayout>
        <StackLayout HorizontalOptions="FillAndExpand">
            <Label Text="Date of Birth"/>
            <DatePicker Date="{Binding DateOfBirth, Mode=TwoWay}"/>
        </StackLayout>
        <StackLayout HorizontalOptions="FillAndExpand">
            <Label Text="Gender"/>
            <Picker x:Name="GenderPicker"
                    SelectedIndex="{Binding SelectedGenderIndex, Mode=TwoWay}"/>
        </StackLayout>
        <StackLayout HorizontalOptions="FillAndExpand">
            <Label Text="Smoking Habit"/>
            <Picker x:Name="SmokingHabitPicker"
                    SelectedIndex="{Binding SelectedSmokingHabitIndex, Mode=TwoWay}"/>
        </StackLayout>
    </StackLayout>
</ContentView>

当渲染时,我会在顶部显示所有3个标签,然后是3个自定义视图,而不是预期的标签,然后是自定义视图模式。如何获得我期待的交替模式?

0 个答案:

没有答案