parent
3c6d683a4f
commit
acae7d1ff0
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:usecase="clr-namespace:BookApp.UseCase"
|
||||
x:Class="BookApp.Composants.RatingView">
|
||||
|
||||
<ContentView.Resources>
|
||||
<usecase:RatingToStarImageConverter x:Key="RatingToStarConverter"/>
|
||||
</ContentView.Resources>
|
||||
|
||||
<StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand">
|
||||
<StackLayout x:Name="StarsLayout" BindableLayout.ItemsSource="{Binding Rating}">
|
||||
<BindableLayout.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Image WidthRequest="30" HeightRequest="30">
|
||||
<Image.Source>
|
||||
<MultiBinding Converter="{StaticResource RatingToStarConverter}">
|
||||
<Binding Path="CurrentRating"/>
|
||||
<Binding Path="."/>
|
||||
</MultiBinding>
|
||||
</Image.Source>
|
||||
</Image>
|
||||
</DataTemplate>
|
||||
</BindableLayout.ItemTemplate>
|
||||
</StackLayout>
|
||||
</StackLayout>
|
||||
</ContentView>
|
@ -0,0 +1,22 @@
|
||||
using BookApp.Model;
|
||||
|
||||
namespace BookApp.Composants;
|
||||
|
||||
public partial class RatingView : ContentView
|
||||
{
|
||||
public static readonly BindableProperty RatingProperty =
|
||||
BindableProperty.Create(nameof(Rating), typeof(Star), typeof(RatingView), default(Star), BindingMode.TwoWay);
|
||||
|
||||
public Star Rating
|
||||
{
|
||||
get { return (Star)GetValue(RatingProperty); }
|
||||
set { SetValue(RatingProperty, value); }
|
||||
}
|
||||
|
||||
|
||||
public RatingView()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.BindingContext = this;
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="BookApp.ContentCollection">
|
||||
<CollectionView ItemsSource="{Binding ItemsSource, Source={x:Reference this}}" Margin="25,0,0,0">
|
||||
<CollectionView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid RowDefinitions="Auto" >
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="25" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image Grid.Column="0" Source="{Binding Icone}"
|
||||
HeightRequest="25"
|
||||
WidthRequest="25" />
|
||||
<Label Grid.Column="1" Text="{Binding Name}"
|
||||
FontAttributes="Bold" Padding="5" VerticalOptions="Center"/>
|
||||
<Grid Grid.Column="2" >
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Column="2" Text="{Binding Name}"
|
||||
FontAttributes="Bold" Padding="5" VerticalOptions="Center"
|
||||
|
||||
/>
|
||||
<Button Grid.Column="2" ImageSource="chevron_right.svg"
|
||||
HeightRequest="35"
|
||||
WidthRequest="35" BackgroundColor="White" HorizontalOptions="End"/>
|
||||
</Grid>
|
||||
<!-- Si veiw cela vaudra peut-être le coup de faire une content view (équiavalent de user control) -->
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</CollectionView.ItemTemplate>
|
||||
</CollectionView>
|
||||
</ContentView>
|
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="BookApp.Pages.DetailBook"
|
||||
Title="Détails du livre">
|
||||
<ContentPage.Content>
|
||||
<StackLayout>
|
||||
<StackLayout x:Name="StarLayout" Grid.Column="0" Orientation="Horizontal" HorizontalOptions="CenterAndExpand">
|
||||
<!-- Les étoiles seront ajoutées ici via le code-behind -->
|
||||
</StackLayout>
|
||||
<Label x:Name="RatingLabel" Grid.Column="1" FontSize="Medium" HorizontalOptions="CenterAndExpand"/>
|
||||
</StackLayout>
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
@ -0,0 +1,67 @@
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace BookApp.Pages;
|
||||
|
||||
public partial class DetailBook : ContentPage
|
||||
{
|
||||
private int maxStars = 5;
|
||||
private int currentRating = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public DetailBook()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
for (int i = 1; i <= maxStars; i++)
|
||||
{
|
||||
var star = new Image
|
||||
{
|
||||
Source = "empty_star.svg", // image d'une étoile vide
|
||||
WidthRequest = 30,
|
||||
HeightRequest = 30
|
||||
};
|
||||
|
||||
int currentStar = i;
|
||||
|
||||
star.GestureRecognizers.Add(new TapGestureRecognizer
|
||||
{
|
||||
Command = new Command(() => StarTapped(currentStar)),
|
||||
});
|
||||
StarLayout.Children.Add(star);
|
||||
}
|
||||
|
||||
UpdateStars();
|
||||
|
||||
BindingContext = this;
|
||||
}
|
||||
|
||||
|
||||
private void StarTapped(int rating)
|
||||
{
|
||||
if (rating > maxStars)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("Erreur : rating trop élevé!");
|
||||
return;
|
||||
}
|
||||
|
||||
currentRating = rating;
|
||||
UpdateStars();
|
||||
RatingLabel.Text = $"Note: {currentRating}/{maxStars}";
|
||||
}
|
||||
|
||||
private void UpdateStars()
|
||||
{
|
||||
for (int i = 0; i < maxStars; i++)
|
||||
{
|
||||
var star = (Image)StarLayout.Children[i];
|
||||
if (i < currentRating)
|
||||
star.Source = "filled_star.svg"; // image d'une étoile remplie
|
||||
else
|
||||
star.Source = "empty_star.svg";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,19 +1,93 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
x:Class="BookApp.Tous"
|
||||
Title="Tous">
|
||||
<ContentPage.ToolbarItems>
|
||||
|
||||
<ToolbarItem Text="Modifier" Priority="0" Order="Primary" />
|
||||
<ToolbarItem IconImageSource="dotnet_bot.svg" Priority="1" Order="Primary" />
|
||||
</ContentPage.ToolbarItems>
|
||||
<ContentPage
|
||||
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:usecase="clr-namespace:BookApp.UseCase"
|
||||
xmlns:composants="clr-namespace:BookApp.Composants"
|
||||
x:Class="BookApp.Tous">
|
||||
<Shell.BackButtonBehavior>
|
||||
<BackButtonBehavior
|
||||
IconOverride="chevron_left.svg"
|
||||
TextOverride="Tous"/>
|
||||
</Shell.BackButtonBehavior>
|
||||
|
||||
<Shell.TitleView>
|
||||
<Label
|
||||
Text="Tous"
|
||||
FontFamily="Strande2"
|
||||
TextColor="White"
|
||||
VerticalTextAlignment="Center"
|
||||
VerticalOptions="CenterAndExpand"
|
||||
HeightRequest="50"
|
||||
FontSize="Medium"
|
||||
HorizontalTextAlignment="Center"/>
|
||||
</Shell.TitleView>
|
||||
|
||||
<ContentPage.ToolbarItems>
|
||||
<ToolbarItem IconImageSource="plus_icone.svg" Priority="1" Order="Primary" />
|
||||
<ToolbarItem IconImageSource="plus_icone.svg" Priority="1" Order="Primary" />
|
||||
</ContentPage.ToolbarItems>
|
||||
|
||||
<ContentPage.Resources>
|
||||
<ResourceDictionary>
|
||||
<usecase:RatingToStarImageConverter x:Key="RatingToStarConverter"/>
|
||||
</ResourceDictionary>
|
||||
</ContentPage.Resources>
|
||||
|
||||
|
||||
<ContentPage.Content>
|
||||
|
||||
<StackLayout>
|
||||
<Label Text="Welcome to Xamarin.Forms!"
|
||||
VerticalOptions="CenterAndExpand"
|
||||
HorizontalOptions="CenterAndExpand" />
|
||||
</StackLayout>
|
||||
<CollectionView ItemsSource="{Binding BookCollection}">
|
||||
<CollectionView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackLayout>
|
||||
<Grid>
|
||||
<!-- Arrière-plan avec BoxView -->
|
||||
<BoxView Color="LightGray" />
|
||||
<!-- Label par-dessus le BoxView -->
|
||||
<Label Text="{Binding Auteur}"
|
||||
Padding="5"
|
||||
Margin="15,0,0,0"
|
||||
TextColor="Black" />
|
||||
</Grid>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Image Grid.Column="0"
|
||||
Source="{Binding ImageBook}"
|
||||
HeightRequest="125"
|
||||
WidthRequest="125"
|
||||
Margin="0,10,0,10"/>
|
||||
<StackLayout Grid.Column="1">
|
||||
<Label Text="{Binding Name}"
|
||||
|
||||
TextColor="Black"/>
|
||||
<Label Text="{Binding Auteur}"
|
||||
|
||||
TextColor="Black"/>
|
||||
<Label
|
||||
Text="{Binding Read}"
|
||||
FontAttributes="Bold"/>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<composants:RatingView Rating="{Binding Note.Rating}"/>
|
||||
</Grid>
|
||||
</StackLayout>
|
||||
</Grid>
|
||||
<BoxView Margin="25,0,0,10" HeightRequest="1" BackgroundColor="LightGray" VerticalOptions="End" />
|
||||
</StackLayout>
|
||||
</DataTemplate>
|
||||
</CollectionView.ItemTemplate>
|
||||
</CollectionView>
|
||||
</ContentPage.Content>
|
||||
</ContentPage>
|
After Width: | Height: | Size: 465 B |
After Width: | Height: | Size: 343 B |
After Width: | Height: | Size: 179 B |
After Width: | Height: | Size: 454 B |
Loading…
Reference in new issue