2017-04-07 92 views
0

我正在寻找一种方式来动态生成卡状的控制,看起来像这些:CardView在Xamarin.Forms

enter image description here

我一直在做一些搜索和发现this article,告诉您如何实现CardView上的一个Xamarin.Android项目。但我使用Xamarin.Forms,所以我可以编译iOS。

我还试图用与ViewCells和一对夫妇StackLayout标签一个ListView,但没能连得接近,这里是代码:

<ListView x:Name="listView"> 
    <ListView.ItemTemplate> 
     <DataTemplate> 
      <ViewCell Height="300"> 
       <StackLayout> 
        <StackLayout Orientation="Horizontal"> 
         <Image Source="{Binding UserAvatar}" /> 
         <Label Text="{Binding UserName}" /> 
        </StackLayout> 
        <Image Source="{Binding BittImage}" /> 
       </StackLayout> 
      </ViewCell> 
     </DataTemplate> 
    </ListView.ItemTemplate> 
</ListView> 

我是很新,Xamarin ,所以如果我错过了一些基本的东西,请让我认识一些人。

+1

只有一些链接... https://github.com/cesartomatis/Xamarin-Forms-CardView https://github.com/keannan5390/xamarin-plugins/tree/master/CardView https://开头forums.xamarin.com/discussion/comment/208640/#Comment_208640 http://danielhindrikes.se/xamarin/xamarin-forms-android-cardview/ –

回答

1

您正处于正确的轨道上。使用ListView,以Frame作为根元素和边距,并根据需要设置ListView的背景颜色。这应该给你看卡片。然后根据需要填写卡片。

<ListView x:Name="listView" BackgroundColor="Gray"> 
    <ListView.ItemTemplate> 
     <DataTemplate> 
      <ViewCell Height="300"> 
       <Frame HasShadow="true" Margin="5"> 
        <StackLayout> 
         <StackLayout Orientation="Horizontal"> 
          <Image Source="{Binding UserAvatar}" /> 
          <Label Text="{Binding UserName}" /> 
         </StackLayout> 
         <Image Source="{Binding BittImage}" /> 
        </StackLayout> 
       </Frame> 
      </ViewCell> 
     </DataTemplate> 
    </ListView.ItemTemplate> 
</ListView> 
+0

谢谢!我正在尝试不同的控制顺序/排列,但它只显示空白帧(每个记录1帧) – Multitut

+0

也许是一个绑定问题... –