Xamarin表单ViewCell Xaml片段

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Xamarin表单ViewCell Xaml片段相关的知识,希望对你有一定的参考价值。

Xamarin Forms ViewCell Xaml snippet
  1. <DataTemplate x:Key="itemTemplate">
  2. <ViewCell>
  3. <ViewCell.View>
  4. <StackLayout Spacing="0" Padding="10,5,10,5" Orientation="Horizontal" HorizontalOptions="FillAndExpand">
  5. <CircleImage Source="{Binding ImageSource}" BorderColor="{x:Static App.BrandColor}" BorderThickness="2" HeightRequest="50"
  6. WidthRequest="50" Aspect="AspectFill" HorizontalOptions="Center" VerticalOptions="LayoutOptions.Center" />
  7. <StackLayout Spacing="0" Padding="10,0,0,0" HorizontalOptions="FillAndExpand">
  8. <Label Text="{Binding Name}" FontFamily="HelveticaNeue-Medium" FontSize="18" TextColor="Black" />
  9. <StackLayout Orientation="Horizontal">
  10. <Label Text="{Binding Distance, StringFormat='{0} Miles Away'" FontAttributes="Bold" FontSize="12" TextColor="#666" />
  11. <Image Source="online.png" HeightRequest="8" WidthRequest="8" IsVisible="{Binding ShouldShowAsOnline}" />
  12. <Label Text="Online" TextColor="{x:Static App.BrandColor}" FontSize="12" IsVisible="{Binding ShouldShowAsOnline}" />
  13. <Image Source="offline.png" HeightRequest="8" WidthRequest="8" IsVisible="{Binding ShouldShowAsOffline}" />
  14. <Label Text="5 hours ago" TextColor="#ddd" FontSize="12" IsVisible="{Binding ShouldShowAsOffline}" />
  15. </StackLayout>
  16. <StackLayout Spacing="3" Orientation="Horizontal">
  17. <Image Source="star.png" HeightRequest="12" WidthRequest= "12" />
  18. <Label Text="{Binding Stars}" FontSize="12" TextColor="Gray" />
  19. </StackLayout>
  20. </StackLayout>
  21. </StackLayout>
  22. </ViewCell.View>
  23. </ViewCell>
  24. </DataTemplate>
  25.  
  26. <ListView ItemsSource="{Binding Data}" ItemTemaplate="{StaticResource itemTemplate}" HasUnevenRows="True" SeparatorColor="#ddd" />

以上是关于Xamarin表单ViewCell Xaml片段的主要内容,如果未能解决你的问题,请参考以下文章

XAML中的Xamarin.Forms ListView AutoHeight

Xamarin 表单:如何引用父绑定

如何在 Xamarin Forms 的可重用 ViewCell 中绑定命令?

Xamarin XAML变量范围不像预期的那样工作

如何知道 ListView 中修改了哪个 Xamarin 表单条目?

如何在Xamarin viewcell或Grid或某处显示默认文件扩展名图标?