2017-11-28 2 views
1

"ValueType"과 같은 속성을 가진 개체 컬렉션이 있는데,이 개체에 대해 표시 할 컨트롤 유형을 반환하는 DataTemplateSelector 클래스를 호출하는이 속성을 기반으로합니다.Xamarin 동적 격자 레이아웃

<control:ControlDataTemplateSelector x:Key="personDataTemplateSelector" 
       RangeTemplate="{StaticResource rangeControl}" 
       EnumTemplate="{StaticResource pickControl}" 
       DateTemplate="{StaticResource dateControl}"/> 

<DataTemplate x:Key="rangeControl"> 
       <ViewCell> 
        <Grid> 
         <Grid.RowDefinitions> 
          <RowDefinition Height="Auto"/> 
          <RowDefinition Height="Auto" /> 
         </Grid.RowDefinitions> 
         <control:ScreenLabel Grid.Row="0" Grid.Column="{Binding Path=SortOrder, Converter={StaticResource sortOrderToColIndexConverter}}" Text="{Binding Path=TraitDescription}" /> 
         <Entry Grid.Row="1" Grid.Column="{Binding Path=SortOrder, Converter={StaticResource sortOrderToColIndexConverter}}" /> 
        </Grid> 
       </ViewCell> 
      </DataTemplate> 
      <DataTemplate x:Key="dateControl"> 
       <ViewCell> 
        <Grid> 
         <Grid.RowDefinitions> 
          <RowDefinition Height="Auto"/> 
          <RowDefinition Height="Auto" /> 
         </Grid.RowDefinitions> 
         <control:ScreenLabel Grid.Row="0" Grid.Column="{Binding Path=SortOrder, Converter={StaticResource sortOrderToColIndexConverter}}" Text="{Binding Path=TraitDescription}" /> 
         <DatePicker Grid.Row="1" Grid.Column="{Binding Path=SortOrder, Converter={StaticResource sortOrderToColIndexConverter}}"></DatePicker> 
        </Grid> 
       </ViewCell> 
      </DataTemplate> 
      <DataTemplate x:Key="pickControl"> 
       <ViewCell> 
        <Grid> 
         <Grid.RowDefinitions> 
          <RowDefinition Height="Auto"/> 
          <RowDefinition Height="Auto" /> 
         </Grid.RowDefinitions> 
         <control:ScreenLabel Grid.Row="0" Grid.Column="{Binding Path=SortOrder, Converter={StaticResource sortOrderToColIndexConverter}}" Text="{Binding Path=TraitDescription}" /> 
         <Picker Grid.Row="1" Grid.Column="{Binding Path=SortOrder, Converter={StaticResource sortOrderToColIndexConverter}}" /> 
        </Grid> 
       </ViewCell> 
      </DataTemplate> 

존재 컬렉션 (9) 오브젝트가 4 개 2 열의 각각의 행을 갖는 5 행과 표보기를 표시해야하는 경우 나 문제, 예를 들어, 두 개의 열 형식 그리드 이러한 표시가 오전 기둥.

현재 코드를 사용하면 지그재그 모양의 레이아웃을 얻을 수 있습니다. 하지만 Like this이 암은 iOS 및 드로이드

답변

0

나는 당신의 ViewCells의 내부 대신 격자의 StackLayouts을 사용에서 작동해야 솔루션을 찾고 몇 가지 제안

이 필요합니다.
 <StackLayout VerticalOptions="FillAndExpand" > 
      <control:ScreenLabel Text="{Binding Path=TraitDescription}" /> 
      <Entry /> 
     </StackLayout> 

당신 있는지 당신의 바인딩이 제대로 돌아오고있다 : 당신은 할 수 있습니까? 속성에 쉼표로 구분 된 태그 확장 설정을 보지 못했습니다.

+0

스택 레이아웃을 사용하는 경우 어떻게 한 열에 2 열을 배치 할 수 있습니까? – Sarav

+0

StackLayout에 추가 : Orientation = "Horizontal" – lowry0031