2017-05-16 5 views
1

TextCellとSwitchCellの要素を持つViewCellを作成しようとしています。
これは私のコード - あるは 'Xamarin.Forms.TextCell'から 'Xamarin.Forms.View'に変換できません

<ListView x:Name="AlarmList" HasUnevenRows="True" > 
     <ListView.ItemTemplate> 
      <DataTemplate> 
       <ViewCell> 
        <StackLayout Orientation="Horizontal"> 
         <TextCell TextColor="#CCCCCC" Text="{Binding Name}" DetailColor="Red" Detail="{Binding Address}"></TextCell> 
         <SwitchCell /> 
        </StackLayout> 
       </ViewCell> 
      </DataTemplate> 
     </ListView.ItemTemplate> 
    </ListView> 

私が手にエラーがある: 'Xamarin.Forms.View'

に 'Xamarin.Forms.TextCell' から変換することはできません


これに代わるものは、これらを使用しています

<Label ></Label> 
<Switch ></Switch> 

これを達成する他の方法はありますか?
enter image description here

+0

細胞は唯一のリストと、表で使用することができ、彼らは他のレイアウト内にネストすることはできません。 – Jason

答えて

6

StackLayout基本的に任意のUI要素であるViewオブジェクトではなく、Cell Sを期待。独自のレイアウトを作成することができない場合は、Xamarin Formsに付属の定義済みセルを使用することもできます。

あなたはすぐに出発しますが、セルは使用できません。だから、それらを失い、ViewCellあなたはどんな方法でレイアウトします。

2

ViewCellには、非セルフォーム要素のみを含めることができると提案されている人もいます。あなたのViewCellを修正するには、このようにそれを行う:

<ListView x:Name="AlarmList" HasUnevenRows="True" > 
     <ListView.ItemTemplate> 
      <DataTemplate> 
       <ViewCell> 
        <StackLayout Orientation="Horizontal"> 
         <Label TextColor="#CCCCCC" Text="{Binding Name}"/> 
         <Switch /> 
        </StackLayout> 
       </ViewCell> 
      </DataTemplate> 
     </ListView.ItemTemplate> 
    </ListView> 
関連する問題