Enhancement of DataBinding

DataBinding
Matheo HERSAN 2 years ago
parent 6e88c66e20
commit cbe5a5259b

@ -1,25 +1,17 @@
namespace MangaMap.Views; namespace MangaMap.Views;
using Model; using Model;
using System.ComponentModel; using System.ComponentModel;
using System.Xml.Linq;
public partial class ficheAnime : ContentPage, INotifyPropertyChanged public partial class ficheAnime : ContentPage, INotifyPropertyChanged
{ {
private Oeuvre animeModel;
public Oeuvre AnimeModel public Manager DataManager { get; set; }
{ public Oeuvre AnimeModel { get; set; }
get { return animeModel; }
set
{
if (animeModel != value)
{
animeModel = value;
OnPropertyChanged(nameof(AnimeModel));
}
}
}
public ficheAnime() public ficheAnime()
{ {
List<string> genres = new List<string>() { "Action", "Aventure" }; List<string> genres = new List<string>() { "Action", "Aventure" };
AnimeModel = new Oeuvre("Evangelion", genres, "Type de l'oeuvre", "Description de l'oeuvre", 5, 12, "Chemin/vers/l'affiche.png"); AnimeModel = new Oeuvre("Evangelion", genres, "Type de l'oeuvre", "Description de l'oeuvre", 5, 12, "Chemin/vers/l'affiche.png");
@ -28,10 +20,13 @@ public partial class ficheAnime : ContentPage, INotifyPropertyChanged
this.BindingContext = this; this.BindingContext = this;
} }
public event PropertyChangedEventHandler PropertyChanged; public ficheAnime(Oeuvre anime)
protected virtual void OnPropertyChanged(string propertyName)
{ {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); AnimeModel = anime;
InitializeComponent();
this.BindingContext = this;
} }
} }

@ -29,80 +29,20 @@
Margin="30" Margin="30"
/> />
<ListView x:Name="a2" ItemsSource="{Binding Oeuvres}"> <HorizontalStackLayout BindableLayout.ItemsSource="{Binding Oeuvres}" Spacing="100" HorizontalOptions="Center">
<ListView.ItemTemplate> <BindableLayout.ItemTemplate>
<DataTemplate> <DataTemplate x:DataType="modeles:Oeuvre">
<ViewCell> <ImageButton
<ImageButton
Style="{StaticResource ImageAnime}" Style="{StaticResource ImageAnime}"
BackgroundColor="Red" BackgroundColor="Red"
Source="{Binding Affiche}" Source="{Binding Affiche}"
Clicked="AnimeImageClicked"
/> />
</ViewCell> <!--<views:StyleBouton -->
</DataTemplate> </DataTemplate>
</ListView.ItemTemplate> </BindableLayout.ItemTemplate>
</ListView>
<HorizontalStackLayout
Spacing="100"
HorizontalOptions="Center">
<views:StyleBouton/>
<ImageButton
Style="{StaticResource ImageAnime}"
BackgroundColor="Orange"
Source="test.jpg"
/>
<views:StyleBouton/>
<views:StyleBouton/>
</HorizontalStackLayout> </HorizontalStackLayout>
<HorizontalStackLayout
Spacing="100"
HorizontalOptions="Center">
<views:StyleBouton/>
<views:StyleBouton/>
<views:StyleBouton/>
<views:StyleBouton/>
</HorizontalStackLayout>
<HorizontalStackLayout
Spacing="100"
HorizontalOptions="Center">
<views:StyleBouton/>
<views:StyleBouton/>
<views:StyleBouton/>
<views:StyleBouton/>
</HorizontalStackLayout>
<HorizontalStackLayout
Spacing="100"
HorizontalOptions="Center">
<views:StyleBouton/>
<views:StyleBouton/>
<views:StyleBouton/>
<views:StyleBouton/>
</HorizontalStackLayout>
<ListView x:Name="a1" ItemsSource="{Binding Utilisateurs}"> <ListView x:Name="a1" ItemsSource="{Binding Utilisateurs}">

@ -2,15 +2,27 @@ namespace MangaMap.Views;
using MangaMap.Model; using MangaMap.Model;
public partial class homePage : ContentPage public partial class homePage : ContentPage
{ {
public Manager my_manager => (App.Current as App).MyManager; public Manager my_manager => (App.Current as App).MyManager;
public homePage() public homePage()
{ {
InitializeComponent();
a1.BindingContext = my_manager; InitializeComponent();
a2.BindingContext = my_manager; BindingContext = my_manager;
BindingContext = my_manager;
} }
private void AnimeImageClicked(object sender, EventArgs e)
{
var selectedAnime = (sender as ImageButton)?.BindingContext as Oeuvre;
if (selectedAnime != null)
{
// Naviguez vers la page de la fiche d'anime en passant l'objet sélectionné
Navigation.PushAsync(new ficheAnime(selectedAnime));
}
}
} }

Loading…
Cancel
Save