2016-10-09 9 views
0

私はXamarinフォームのListViewを使用しています。これまでは、カスタムDataTemplateを使用していくつかのデータを表示しました。さて、私はこれを拡張して、画像の中/上のテキストを表示したいと思います。このような何か:Xamarin Froms ListViewのカスタムテンプレート

enter image description here

は、これは私がこれまで使用している、コードです。ただし、この場合、テキストは画像上に表示されます。

<ListView x:Name="MyListView" 
      ItemsSource="{Binding myData}" 
      RowHeight="190" 
      HasUnevenRows="True"> 
    <ListView.ItemTemplate> 
     <DataTemplate> 
     <ViewCell> 
      <ViewCell.View> 
      <StackLayout Padding="10" Orientation="Vertical"> 
       <Label Text="{Binding Title}" 
        FontSize="Large" 
        VerticalOptions="Center" 
        TextColor="#31659e"> 
       </Label>     
       <Image Source="http://www.someurl.com/images/image1.jpg" Aspect="AspectFill"></Image>     
      </StackLayout> 
      </ViewCell.View> 
     </ViewCell> 
     </DataTemplate> 
    </ListView.ItemTemplate> 
    </ListView> 

最初の画像の結果はどのように達成できますか?

誰かがそれを行う方法の例/リンク/ヒントを持っているなら、それは非常に役に立ちます。

おかげ

+0

boolプロパティをIsVisableプロパティにバインドし、他のアイテムを無効にすることができます –

+0

この[snppt](https://snppts.io/snippet/23)を見て、これらの種類のプラットフォームを作成しようとしていますデザイン。これはあなたが後にしている背景画像の上に何らかのテキストを持っています。 –

答えて

1

あなたはRelativeLayoutを使用することができます。それはあなたのデータテンプレートViewCell.View

<RelativeLayout> 
    <!-- Background --> 
    <Image Source="http://www.someurl.com/images/image1.jpg" Aspect="AspectFill" 
      RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width}" 
      RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height}" /> 
    <!-- Text --> 
    <StackLayout Padding="10" Orientation="Vertical" VerticalOptions="EndAndExpand" 
       RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width}" 
       RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height}" > 
     <Label Text="{Binding Title}" 
      FontSize="Large" 
      TextColor="#31659e"> 
     </Label> 
     <Label Text="{Binding SubTitle}" 
      TextColor="#31659e"> 
     </Label> 
    </StackLayout> 
</RelativeLayout> 

これは、画像と同じ高さにstacklayoutを伸ばし及びbotttomでStackLayoutのコンテンツを揃えるには、このようになります。

+0

そのコードは期待通りに機能します。私はちょうどいくつかの微調整をした、ありがとう – MikePR

+0

今、データは上記の画像として表示されています。テキストのみが下部の代わりに上部に表示されています。私はそれに取り組んでいます。しかし、一般的にコードは機能します。 – MikePR

関連する問題