parent
ca5debb924
commit
5df7c6edb8
Binary file not shown.
@ -1,54 +1,73 @@
|
||||
using CommunityToolkit.Maui.Behaviors;
|
||||
using Microsoft.Maui.Controls;
|
||||
using System.Linq;
|
||||
|
||||
namespace PocketBook;
|
||||
|
||||
public partial class Stars : ContentView
|
||||
namespace PocketBook
|
||||
{
|
||||
public static readonly BindableProperty NbStarsProperty =
|
||||
BindableProperty.Create(nameof(NbStars), typeof(int), typeof(Stars), defaultValue: 0, propertyChanged: OnNbStarsChanged);
|
||||
|
||||
public int NbStars
|
||||
public partial class Stars : ContentView
|
||||
{
|
||||
get { return (int)GetValue(NbStarsProperty); }
|
||||
set { SetValue(NbStarsProperty, value); }
|
||||
}
|
||||
public static readonly BindableProperty NombreEtoileProperty =
|
||||
BindableProperty.Create(nameof(NombreEtoile), typeof(int), typeof(Stars), defaultValue: 0, propertyChanged: OnNbStarsChanged);
|
||||
|
||||
public Stars()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
public int NombreEtoile
|
||||
{
|
||||
get => (int)GetValue(NombreEtoileProperty);
|
||||
set => SetValue(NombreEtoileProperty, value);
|
||||
}
|
||||
|
||||
private static void OnNbStarsChanged(BindableObject bindable, object oldValue, object newValue)
|
||||
{
|
||||
if (bindable is Stars stars)
|
||||
public Stars()
|
||||
{
|
||||
stars.UpdateStars();
|
||||
InitializeComponent();
|
||||
InitializeStars();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateStars()
|
||||
{
|
||||
int z = 0;
|
||||
private void InitializeStars()
|
||||
{
|
||||
var behaviorGrey = new IconTintColorBehavior
|
||||
{
|
||||
TintColor = Color.FromArgb("#E6E6E6"),
|
||||
};
|
||||
|
||||
var behaviorYellow = new IconTintColorBehavior
|
||||
foreach (Image i in StarsList.Children.OfType<Image>())
|
||||
{
|
||||
i.Behaviors.Add(behaviorGrey);
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnNbStarsChanged(BindableObject bindable, object oldValue, object newValue)
|
||||
{
|
||||
TintColor = Color.FromArgb("#FFFF00"),
|
||||
};
|
||||
if (bindable is Stars stars)
|
||||
{
|
||||
stars.UpdateStars();
|
||||
}
|
||||
}
|
||||
|
||||
var behaviorGrey = new IconTintColorBehavior
|
||||
private void UpdateStars()
|
||||
{
|
||||
TintColor = Color.FromArgb("#E6E6E6"),
|
||||
};
|
||||
int z = 0;
|
||||
|
||||
var behaviorGrey = new IconTintColorBehavior
|
||||
{
|
||||
TintColor = Color.FromArgb("#E6E6E6"),
|
||||
};
|
||||
|
||||
foreach (Image i in StarsList.Children.Where(c => c is Image))
|
||||
{
|
||||
if (z < NbStars)
|
||||
var behaviorYellow = new IconTintColorBehavior
|
||||
{
|
||||
TintColor = Color.FromArgb("#FFFF00"),
|
||||
};
|
||||
|
||||
foreach (Image i in StarsList.Children.OfType<Image>())
|
||||
{
|
||||
i.Behaviors.Add(behaviorYellow);
|
||||
if (z < NombreEtoile)
|
||||
{
|
||||
i.Behaviors.Add(behaviorYellow);
|
||||
}
|
||||
else
|
||||
{
|
||||
i.Behaviors.Add(behaviorGrey);
|
||||
}
|
||||
z++;
|
||||
}
|
||||
else i.Behaviors.Add(behaviorGrey);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue