Fixes the rating control
This commit is contained in:
parent
b6bfadb7b4
commit
d642ff3cad
10 changed files with 157 additions and 58 deletions
|
|
@ -87,8 +87,7 @@ namespace BookAStar.Behaviors
|
||||||
BindableProperty.Create("IsStarred",
|
BindableProperty.Create("IsStarred",
|
||||||
typeof(bool),
|
typeof(bool),
|
||||||
typeof(StarBehavior),
|
typeof(StarBehavior),
|
||||||
false,
|
false);
|
||||||
propertyChanged: OnIsStarredChanged);
|
|
||||||
|
|
||||||
public bool IsStarred
|
public bool IsStarred
|
||||||
{
|
{
|
||||||
|
|
@ -100,8 +99,7 @@ namespace BookAStar.Behaviors
|
||||||
{
|
{
|
||||||
StarBehavior behavior = (StarBehavior)bindable;
|
StarBehavior behavior = (StarBehavior)bindable;
|
||||||
|
|
||||||
if ((bool)newValue)
|
|
||||||
{
|
|
||||||
string groupName = behavior.GroupName;
|
string groupName = behavior.GroupName;
|
||||||
List<StarBehavior> behaviors = null;
|
List<StarBehavior> behaviors = null;
|
||||||
|
|
||||||
|
|
@ -126,8 +124,14 @@ namespace BookAStar.Behaviors
|
||||||
if (item == behavior)
|
if (item == behavior)
|
||||||
{
|
{
|
||||||
itemReached = true;
|
itemReached = true;
|
||||||
item.IsStarred = true;
|
// whould try to call this method again
|
||||||
position = count;
|
// Assert item.IsStarred == newValue;
|
||||||
|
|
||||||
|
// There are **6** positions, from 0 to five stars.
|
||||||
|
if ((bool)newValue)
|
||||||
|
position = count;
|
||||||
|
else position = count - 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
if (item != behavior && itemReached)
|
if (item != behavior && itemReached)
|
||||||
item.IsStarred = false;
|
item.IsStarred = false;
|
||||||
|
|
@ -135,8 +139,7 @@ namespace BookAStar.Behaviors
|
||||||
item.Rating = position;
|
item.Rating = position;
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -158,12 +161,14 @@ namespace BookAStar.Behaviors
|
||||||
view.GestureRecognizers.Remove(tapRecognizer);
|
view.GestureRecognizers.Remove(tapRecognizer);
|
||||||
tapRecognizer.Tapped -= OnTapRecognizerTapped;
|
tapRecognizer.Tapped -= OnTapRecognizerTapped;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnTapRecognizerTapped(object sender, EventArgs args)
|
void OnTapRecognizerTapped(object sender, EventArgs args)
|
||||||
{
|
{
|
||||||
// TODO HACK: PropertyChange does not fire, if the value is not changed :-(
|
// TODO HACK: PropertyChange does not fire, if the value is not changed :-(
|
||||||
IsStarred = false;
|
bool currentIsStarred = (bool) GetValue(IsStarredProperty);
|
||||||
IsStarred = true;
|
SetValue(IsStarredProperty, !currentIsStarred);
|
||||||
|
// does not lead to the call of:
|
||||||
|
OnIsStarredChanged(this,currentIsStarred,!currentIsStarred);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -314,10 +314,10 @@
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Images\Validation\error.png" />
|
<EmbeddedResource Include="Images\Validation\error.png" />
|
||||||
<Content Include="Images\Validation\star_outline.png" />
|
<EmbeddedResource Include="Images\Validation\star_outline.png" />
|
||||||
<Content Include="Images\Validation\star_selected.png" />
|
<EmbeddedResource Include="Images\Validation\star_selected.png" />
|
||||||
<Content Include="Images\Validation\success.png" />
|
<EmbeddedResource Include="Images\Validation\success.png" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="Views\RatingView.xaml">
|
<EmbeddedResource Include="Views\RatingView.xaml">
|
||||||
|
|
|
||||||
|
|
@ -22,12 +22,12 @@ namespace BookAStar.Model.Workflow
|
||||||
/// In db, they are separated by <c>:</c>
|
/// In db, they are separated by <c>:</c>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public List<string> AttachedGraphicList { get; set; }
|
public List<string> AttachedGraphics { get; set; }
|
||||||
|
|
||||||
public string AttachedGraphicsString
|
public string AttachedGraphicsString
|
||||||
{
|
{
|
||||||
get { return AttachedGraphicList==null?null:string.Join(":", AttachedGraphicList); }
|
get { return AttachedGraphics==null?null:string.Join(":", AttachedGraphics); }
|
||||||
set { AttachedGraphicList = value.Split(':').ToList(); }
|
set { AttachedGraphics = value.Split(':').ToList(); }
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// List of attached files
|
/// List of attached files
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
xmlns:local="clr-namespace:BookAStar;assembly=BookAStar"
|
xmlns:local="clr-namespace:BookAStar;assembly=BookAStar"
|
||||||
xmlns:views="clr-namespace:BookAStar.Views;assembly=BookAStar"
|
xmlns:views="clr-namespace:BookAStar.Views;assembly=BookAStar"
|
||||||
|
xmlns:extensions="clr-namespace:BookAStar.Extensions;assembly=BookAStar"
|
||||||
x:Class="BookAStar.Pages.DashboardPage"
|
x:Class="BookAStar.Pages.DashboardPage"
|
||||||
xmlns:lc="clr-namespace:XLabs.Forms.Controls;assembly=XLabs.Forms"
|
xmlns:lc="clr-namespace:XLabs.Forms.Controls;assembly=XLabs.Forms"
|
||||||
xmlns:lb="clr-namespace:XLabs.Forms.Behaviors;assembly=XLabs.Forms"
|
xmlns:lb="clr-namespace:XLabs.Forms.Behaviors;assembly=XLabs.Forms"
|
||||||
|
|
@ -19,26 +20,35 @@
|
||||||
</ContentPage.Resources>
|
</ContentPage.Resources>
|
||||||
<ScrollView>
|
<ScrollView>
|
||||||
<StackLayout Orientation="Vertical" >
|
<StackLayout Orientation="Vertical" >
|
||||||
|
|
||||||
|
<Label Text="Compte utilisateur" StyleClass="Header">
|
||||||
|
</Label>
|
||||||
<lc:GesturesContentView>
|
<lc:GesturesContentView>
|
||||||
<Frame>
|
<StackLayout>
|
||||||
<Label Text="Compte utilisateur" StyleClass="Header">
|
<Frame>
|
||||||
</Label>
|
<lb:Gestures.Interests>
|
||||||
<lb:Gestures.Interests>
|
<lb:GestureCollection>
|
||||||
<lb:GestureCollection>
|
<lb:GestureInterest GestureType="LongPress"
|
||||||
<lb:GestureInterest GestureType="LongPress"
|
GestureCommand="{Binding UserNameGesture}"
|
||||||
GestureCommand="{Binding UserNameGesture}"
|
/>
|
||||||
GestureParameter="LongPress" />
|
</lb:GestureCollection>
|
||||||
</lb:GestureCollection>
|
</lb:Gestures.Interests>
|
||||||
|
<StackLayout>
|
||||||
|
|
||||||
<Image Source="{Binding Avatar}" Aspect="AspectFit" VisualElement.HeightRequest="{StaticResource BigUserAvatarSize}" />
|
<Image Source="{Binding Avatar}" Aspect="AspectFit" VisualElement.HeightRequest="{StaticResource BigUserAvatarSize}" />
|
||||||
|
|
||||||
<Label Text="{Binding UserName}" Style="{StaticResource LabelPageHeadingStyle}"
|
<Label Text="{Binding UserName}" Style="{StaticResource LabelPageHeadingStyle}"
|
||||||
HorizontalTextAlignment="Center"
|
HorizontalTextAlignment="Center"
|
||||||
LineBreakMode="WordWrap" XAlign="Center"
|
LineBreakMode="WordWrap" XAlign="Center"
|
||||||
></Label>
|
></Label>
|
||||||
<views:RatingView Rating="{Binding Rating}"/>
|
</StackLayout>
|
||||||
</lb:Gestures.Interests>
|
</Frame>
|
||||||
</Frame>
|
<views:RatingView Rating="{Binding Rating}"/>
|
||||||
|
</StackLayout>
|
||||||
|
|
||||||
</lc:GesturesContentView>
|
</lc:GesturesContentView>
|
||||||
|
|
||||||
|
|
||||||
<Button Text="{Binding PerformerStatus}" Clicked="OnViewPerformerStatus" />
|
<Button Text="{Binding PerformerStatus}" Clicked="OnViewPerformerStatus" />
|
||||||
<Button Text="{Binding UserQueries}" Clicked="OnViewUserQueries" />
|
<Button Text="{Binding UserQueries}" Clicked="OnViewUserQueries" />
|
||||||
<StackLayout Orientation="Horizontal" >
|
<StackLayout Orientation="Horizontal" >
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
xmlns:local="clr-namespace:BookAStar;assembly=BookAStar"
|
xmlns:local="clr-namespace:BookAStar;assembly=BookAStar"
|
||||||
|
xmlns:converters="clr-namespace:BookAStar.Converters;assembly=BookAStar"
|
||||||
xmlns:views="clr-namespace:BookAStar.Views;assembly=BookAStar"
|
xmlns:views="clr-namespace:BookAStar.Views;assembly=BookAStar"
|
||||||
xmlns:behaviors="clr-namespace:BookAStar.Behaviors;assembly=BookAStar"
|
xmlns:behaviors="clr-namespace:BookAStar.Behaviors;assembly=BookAStar"
|
||||||
xmlns:extensions="clr-namespace:BookAStar.Extensions;assembly=BookAStar"
|
xmlns:extensions="clr-namespace:BookAStar.Extensions;assembly=BookAStar"
|
||||||
|
|
@ -15,24 +16,25 @@
|
||||||
<Style TargetType="Button">
|
<Style TargetType="Button">
|
||||||
<Setter Property="Style" Value="{StaticResource ButtonStyle}" />
|
<Setter Property="Style" Value="{StaticResource ButtonStyle}" />
|
||||||
</Style>
|
</Style>
|
||||||
<local:BooleanToObjectConverter x:Key="boolToStyleImage" x:TypeArguments="Style">
|
<converters:BooleanToObjectConverter x:Key="boolToStyleImage" x:TypeArguments="Style">
|
||||||
|
|
||||||
<local:BooleanToObjectConverter.FalseObject>
|
|
||||||
<Style TargetType="Image">
|
|
||||||
<Setter Property="HeightRequest" Value="20" />
|
|
||||||
<Setter Property="Source" Value="{extensions:ImageResource Samples.Images.error.png}" />
|
|
||||||
</Style>
|
|
||||||
</local:BooleanToObjectConverter.FalseObject>
|
|
||||||
|
|
||||||
<local:BooleanToObjectConverter.TrueObject>
|
<converters:BooleanToObjectConverter.FalseObject>
|
||||||
<Style TargetType="Image">
|
<Style TargetType="Image">
|
||||||
<Setter Property="HeightRequest" Value="20" />
|
<Setter Property="HeightRequest" Value="20" />
|
||||||
<Setter Property="Source" Value="{extensions:ImageResource Samples.Images.success.png}" />
|
<Setter Property="Source" Value="{extensions:ImageResource BookAStar.Images.Validation.error.png}" />
|
||||||
</Style>
|
</Style>
|
||||||
</local:BooleanToObjectConverter.TrueObject>
|
</converters:BooleanToObjectConverter.FalseObject>
|
||||||
</local:BooleanToObjectConverter>
|
|
||||||
|
<converters:BooleanToObjectConverter.TrueObject>
|
||||||
|
<Style TargetType="Image">
|
||||||
|
<Setter Property="HeightRequest" Value="20" />
|
||||||
|
<Setter Property="Source" Value="{extensions:ImageResource BookAStar.Images.Validation.success.png}" />
|
||||||
|
</Style>
|
||||||
|
</converters:BooleanToObjectConverter.TrueObject>
|
||||||
|
</converters:BooleanToObjectConverter>
|
||||||
|
|
||||||
</ResourceDictionary>
|
|
||||||
|
</ResourceDictionary>
|
||||||
</ContentPage.Resources>
|
</ContentPage.Resources>
|
||||||
<StackLayout x:Name="mainStackLayout">
|
<StackLayout x:Name="mainStackLayout">
|
||||||
<Label Text="Description de la ligne de facture" Style="{StaticResource InputLabelStyle}"></Label>
|
<Label Text="Description de la ligne de facture" Style="{StaticResource InputLabelStyle}"></Label>
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,20 @@ namespace BookAStar.ViewModels
|
||||||
data.Description = value;
|
data.Description = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public decimal UnitaryCost
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return data.UnitaryCost;
|
||||||
|
}
|
||||||
|
|
||||||
|
set
|
||||||
|
{
|
||||||
|
SetProperty<decimal>(ref unitaryCost, value, "UnitaryCost");
|
||||||
|
data.UnitaryCost = value;
|
||||||
|
UnitaryCostText = value.ToString(unitCostFormat, CultureInfo.InvariantCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
protected int durationValue;
|
protected int durationValue;
|
||||||
public int DurationValue
|
public int DurationValue
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ namespace BookAStar.ViewModels
|
||||||
|
|
||||||
internal class DashboardViewModel : ViewModel
|
internal class DashboardViewModel : ViewModel
|
||||||
{
|
{
|
||||||
|
public int Rating { get; set; }
|
||||||
|
|
||||||
public string UserId
|
public string UserId
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,10 @@ namespace BookAStar.ViewModels
|
||||||
{
|
{
|
||||||
Data = data;
|
Data = data;
|
||||||
if (data.AttachedFiles == null) data.AttachedFiles = new List<string>();
|
if (data.AttachedFiles == null) data.AttachedFiles = new List<string>();
|
||||||
if (data.AttachedGraphicList == null) data.AttachedGraphicList = new List<string>();
|
if (data.AttachedGraphics == null) data.AttachedGraphics = new List<string>();
|
||||||
if (data.Bill == null) data.Bill = new List<BillingLine>();
|
if (data.Bill == null) data.Bill = new List<BillingLine>();
|
||||||
AttachedFiles = new ObservableCollection<string>(data.AttachedFiles);
|
AttachedFiles = new ObservableCollection<string>(data.AttachedFiles);
|
||||||
AttachedGraphicList = new ObservableCollection<string>(data.AttachedGraphicList);
|
AttachedGraphicList = new ObservableCollection<string>(data.AttachedGraphics);
|
||||||
Bill = new ObservableCollection<BillingLine>(data.Bill);
|
Bill = new ObservableCollection<BillingLine>(data.Bill);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
|
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
xmlns:local="clr-namespace:BookAStar;assembly=BookAStar"
|
xmlns:local="clr-namespace:BookAStar;assembly=BookAStar"
|
||||||
|
xmlns:extensions="clr-namespace:BookAStar.Extensions;assembly=BookAStar"
|
||||||
xmlns:behaviors="clr-namespace:BookAStar.Behaviors;assembly=BookAStar"
|
xmlns:behaviors="clr-namespace:BookAStar.Behaviors;assembly=BookAStar"
|
||||||
xmlns:converters="clr-namespace:BookAStar.Converters;assembly=BookAStar"
|
xmlns:converters="clr-namespace:BookAStar.Converters;assembly=BookAStar"
|
||||||
x:Class="BookAStar.Views.RatingView">
|
x:Class="BookAStar.Views.RatingView">
|
||||||
|
|
@ -13,10 +14,10 @@
|
||||||
<behaviors:StarBehavior x:Name="starOne" GroupName="myStar"/>
|
<behaviors:StarBehavior x:Name="starOne" GroupName="myStar"/>
|
||||||
</Grid.Behaviors>
|
</Grid.Behaviors>
|
||||||
<Image x:Name="starBlankOne"
|
<Image x:Name="starBlankOne"
|
||||||
Source="{local:ImageResource BookAStar.Images.star_outline.png}" />
|
Source="{extensions:ImageResource BookAStar.Images.Validation.star_outline.png}" />
|
||||||
|
|
||||||
<Image x:Name="starSelectedOne"
|
<Image x:Name="starSelectedOne"
|
||||||
Source="{local:ImageResource BookAStar.Images.star_selected.png}"
|
Source="{extensions:ImageResource BookAStar.Images.Validation.star_selected.png}"
|
||||||
IsVisible="{Binding Source={x:Reference starOne},
|
IsVisible="{Binding Source={x:Reference starOne},
|
||||||
Path=IsStarred}"/>
|
Path=IsStarred}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
@ -25,10 +26,10 @@
|
||||||
<behaviors:StarBehavior x:Name="starTwo" GroupName="myStar"/>
|
<behaviors:StarBehavior x:Name="starTwo" GroupName="myStar"/>
|
||||||
</Grid.Behaviors>
|
</Grid.Behaviors>
|
||||||
<Image x:Name="starBlankTwo"
|
<Image x:Name="starBlankTwo"
|
||||||
Source="{local:ImageResource BookAStar.Images.star_outline.png}" />
|
Source="{extensions:ImageResource BookAStar.Images.Validation.star_outline.png}" />
|
||||||
|
|
||||||
<Image x:Name="starSelectedTwo"
|
<Image x:Name="starSelectedTwo"
|
||||||
Source="{local:ImageResource BookAStar.Images.star_selected.png}"
|
Source="{extensions:ImageResource BookAStar.Images.Validation.star_selected.png}"
|
||||||
IsVisible="{Binding Source={x:Reference starTwo},
|
IsVisible="{Binding Source={x:Reference starTwo},
|
||||||
Path=IsStarred}"/>
|
Path=IsStarred}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
@ -37,10 +38,10 @@
|
||||||
<behaviors:StarBehavior x:Name="starThree" GroupName="myStar"/>
|
<behaviors:StarBehavior x:Name="starThree" GroupName="myStar"/>
|
||||||
</Grid.Behaviors>
|
</Grid.Behaviors>
|
||||||
<Image x:Name="starBlankThree"
|
<Image x:Name="starBlankThree"
|
||||||
Source="{local:ImageResource BookAStar.Images.star_outline.png}" />
|
Source="{extensions:ImageResource BookAStar.Images.Validation.star_outline.png}" />
|
||||||
|
|
||||||
<Image x:Name="starSelectedThree"
|
<Image x:Name="starSelectedThree"
|
||||||
Source="{local:ImageResource BookAStar.Images.star_selected.png}"
|
Source="{extensions:ImageResource BookAStar.Images.Validation.star_selected.png}"
|
||||||
IsVisible="{Binding Source={x:Reference starThree},
|
IsVisible="{Binding Source={x:Reference starThree},
|
||||||
Path=IsStarred}"/>
|
Path=IsStarred}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
@ -49,10 +50,10 @@
|
||||||
<behaviors:StarBehavior x:Name="starFour" GroupName="myStar"/>
|
<behaviors:StarBehavior x:Name="starFour" GroupName="myStar"/>
|
||||||
</Grid.Behaviors>
|
</Grid.Behaviors>
|
||||||
<Image x:Name="starBlankFour"
|
<Image x:Name="starBlankFour"
|
||||||
Source="{local:ImageResource BookAStar.Images.star_outline.png}" />
|
Source="{extensions:ImageResource BookAStar.Images.Validation.star_outline.png}" />
|
||||||
|
|
||||||
<Image x:Name="starSelectedFour"
|
<Image x:Name="starSelectedFour"
|
||||||
Source="{local:ImageResource BookAStar.Images.star_selected.png}"
|
Source="{extensions:ImageResource BookAStar.Images.Validation.star_selected.png}"
|
||||||
IsVisible="{Binding Source={x:Reference starFour},
|
IsVisible="{Binding Source={x:Reference starFour},
|
||||||
Path=IsStarred}"/>
|
Path=IsStarred}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
@ -61,10 +62,10 @@
|
||||||
<behaviors:StarBehavior x:Name="starFive" GroupName="myStar"/>
|
<behaviors:StarBehavior x:Name="starFive" GroupName="myStar"/>
|
||||||
</Grid.Behaviors>
|
</Grid.Behaviors>
|
||||||
<Image x:Name="starBlankFive"
|
<Image x:Name="starBlankFive"
|
||||||
Source="{local:ImageResource BookAStar.Images.star_outline.png}" />
|
Source="{extensions:ImageResource BookAStar.Images.Validation.star_outline.png}" />
|
||||||
|
|
||||||
<Image x:Name="starSelectedFive"
|
<Image x:Name="starSelectedFive"
|
||||||
Source="{local:ImageResource BookAStar.Images.star_selected.png}"
|
Source="{extensions:ImageResource BookAStar.Images.Validation.star_selected.png}"
|
||||||
IsVisible="{Binding Source={x:Reference starFive},
|
IsVisible="{Binding Source={x:Reference starFive},
|
||||||
Path=IsStarred}"/>
|
Path=IsStarred}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
@ -72,16 +73,14 @@
|
||||||
<StackLayout>
|
<StackLayout>
|
||||||
<StackLayout.Resources>
|
<StackLayout.Resources>
|
||||||
<ResourceDictionary>
|
<ResourceDictionary>
|
||||||
<local:RatingText x:Key="ratingText" />
|
<converters:RatingText x:Key="ratingText" />
|
||||||
<Style TargetType="Label" BasedOn="{StaticResource baseStyle}">
|
<Style TargetType="Label" BasedOn="{StaticResource LabelStyle}">
|
||||||
<Setter Property="TextColor" Value="#4CAF50" />
|
<Setter Property="TextColor" Value="#4CAF50" />
|
||||||
</Style>
|
</Style>
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
</StackLayout.Resources>
|
</StackLayout.Resources>
|
||||||
<Label Text="{Binding Source={x:Reference starFive},
|
<Label Text="{Binding Source={x:Reference starFive}, Path=Rating, Converter={StaticResource ratingText}}" ></Label>
|
||||||
Path=Rating, Converter={StaticResource ratingText}}" ></Label>
|
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
<Button Text="Submit"/>
|
|
||||||
</StackLayout>
|
</StackLayout>
|
||||||
|
|
||||||
</ContentView.Content>
|
</ContentView.Content>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using BookAStar.Behaviors;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
@ -10,9 +11,75 @@ namespace BookAStar.Views
|
||||||
{
|
{
|
||||||
public partial class RatingView : ContentView
|
public partial class RatingView : ContentView
|
||||||
{
|
{
|
||||||
|
protected int rating;
|
||||||
|
|
||||||
|
public int Rating {
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return rating;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value != rating)
|
||||||
|
{
|
||||||
|
if (value < 0 || value > 5)
|
||||||
|
{
|
||||||
|
SetValue(RatingProperty, 0);
|
||||||
|
rating = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetValue(RatingProperty, value);
|
||||||
|
rating = value;
|
||||||
|
}
|
||||||
|
starBehaviors[4].SetValue(StarBehavior.RatingProperty, rating);
|
||||||
|
for (int i = 0; i < rating && i < 5; i++)
|
||||||
|
starBehaviors[i].SetValue(StarBehavior.IsStarredProperty, true);
|
||||||
|
for (int i = rating; i < 5 && i >= 0; i++)
|
||||||
|
starBehaviors[i].SetValue(StarBehavior.IsStarredProperty, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool isStarred;
|
||||||
|
public bool IsStarred
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return isStarred;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
SetValue(IsStarredProperty, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
StarBehavior[] starBehaviors;
|
||||||
|
public static BindableProperty IsStarredProperty = BindableProperty.Create(
|
||||||
|
propertyName: "IsStarred",
|
||||||
|
returnType: typeof(bool),
|
||||||
|
declaringType: typeof(RatingView),
|
||||||
|
defaultValue: false,
|
||||||
|
defaultBindingMode: BindingMode.TwoWay
|
||||||
|
);
|
||||||
|
|
||||||
|
public static BindableProperty RatingProperty = BindableProperty.Create(
|
||||||
|
propertyName: "Rating",
|
||||||
|
returnType: typeof(int),
|
||||||
|
declaringType: typeof(RatingView),
|
||||||
|
defaultValue: 0,
|
||||||
|
defaultBindingMode: BindingMode.TwoWay
|
||||||
|
);
|
||||||
|
|
||||||
public RatingView()
|
public RatingView()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
starBehaviors = new StarBehavior[5]
|
||||||
|
{
|
||||||
|
starOne, starTwo, starThree, starFour, starFive
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue