如何在Xamarin Cross Platform xaml中添加评级栏

时间:2016-10-07 09:01:14

标签: c# .net xaml xamarin xamarin.forms

我想在xamarin便携式课程中添加评级栏。我经常搜索过 使用syncfusion评级栏但没有进展。我使用过nuget第三方工具。但评级栏不显示。我想使用像syncfusion这样的内置工具 并显示评级

我的代码

   <?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>

2 个答案:

答案 0 :(得分:0)

来自我们的传福音团队的Nish在博客文章中讨论了在Xamarin.Forms中创建评级控件

您可以在此处找到来源并详细了解它:https://blog.xamarin.com/behaviors-in-xamarin-forms/

答案 1 :(得分:0)

您可以参考以下博客

使用xamarin表单(自定义控件)创建评分栏的步骤 https://xamarincodingtutorial.blogspot.com/2019/04/p_29.html