如何在Xamarin跨平台xaml中添加评级栏
本文关键字:添加 xaml Xamarin 跨平台 | 更新日期: 2023-09-27 18:11:56
我想在xamarin portable类中添加评级栏。我找了很多地方使用综合评分条但没有进展。我使用了nuget第三方工具。但评级栏不显示。我想使用像syncfusion这样的内置工具并显示评级
My Code
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyVoucherSpy.Portable.Views.AboutPage"
xmlns:rating="clr- namespace:Syncfusion.SfRating.XForms;assembly=Syncfusion.SfRating.XForms"
>
<ListView
CachingStrategy="RecycleElement"
SeparatorColor="Transparent"
HasUnevenRows="True"
x:Name="listView">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid x:Name="LayoutRoot">
Rating bar I had used
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="300"/>
</Grid.RowDefinitions>
<BoxView BackgroundColor="#700AB9" />
<Image Source="{Binding DefaultImageUrl}" HeightRequest="500" >
</Image>
<StackLayout>
<Image Source="hrtgray.png" HeightRequest="20" Margin="0,10,350,0" WidthRequest="20" />
<Label Margin="40,-25,0,100" Text="{Binding Favourite}" FontSize="Small" TextColor="#ffffff"/>
<Label Margin="20,0,0,0" Text="{Binding CategoryName}" TextColor="#ffffff" FontSize="Small"/>
<Label Margin="20,0,0,0" Text="{Binding Headline}" TextColor="#ffffff" FontSize="Large"/>
<Label Margin="100,0,0,10" Text="{Binding UserRated}" TextColor="#ffffff" FontSize="Small"/>
<Image Source="map.png" HeightRequest="15" Margin="0,30,0,0" WidthRequest="15" />
<Label Margin="0,-25,0,100" Text="{Binding Miles}" TextColor="#ffffff" FontSize="Small"/>
</StackLayout>
<rating:SfRating x:Name="rating" ItemCount="3" />
<!--<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="5"/>
</Grid.RowDefinitions>
<Label Text="{Binding Headline}" TextColor="#FFFFFF"/>
</Grid>-->
<!--<Image Grid.Row="2" Source="hrtgray"/>
<Label Grid.Row="4" Text="{Binding Exclusive}" TextColor="#FFFFFF"/>
<Label Text="{Binding CategoryName}" TextColor="#FFFFFF"/>
<Label Text="{Binding UserRated}" TextColor="#FFFFFF"/>
<Label Text="{Binding AverageRated}" TextColor="#FFFFFF"/>
<Label Text="{Binding Favourite}" TextColor="#FFFFFF"/>
<Label Text="{Binding Miles}" TextColor="#FFFFFF"/>-->
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage.Content>
您可以参考以下博客
使用xamarin表单(自定义控件)创建评级栏https://xamarincodingtutorial.blogspot.com/2019/04/p_29.html
我们布道团队的Nish写了一篇博文讨论在Xamarin中创建评级控制。形式
您可以在这里找到源代码并阅读更多信息:https://blog.xamarin.com/behaviors-in-xamarin-forms/