Enhancement of DataBinding

DataBinding
Matheo HERSAN 2 years ago
parent 6e88c66e20
commit cbe5a5259b

@ -1,25 +1,17 @@
namespace MangaMap.Views;
using Model;
using System.ComponentModel;
using System.Xml.Linq;
public partial class ficheAnime : ContentPage, INotifyPropertyChanged
{
private Oeuvre animeModel;
public Oeuvre AnimeModel
{
get { return animeModel; }
set
{
if (animeModel != value)
{
animeModel = value;
OnPropertyChanged(nameof(AnimeModel));
}
}
}
public Manager DataManager { get; set; }
public Oeuvre AnimeModel { get; set; }
public ficheAnime()
{
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");
@ -28,10 +20,13 @@ public partial class ficheAnime : ContentPage, INotifyPropertyChanged
this.BindingContext = this;
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
public ficheAnime(Oeuvre anime)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
AnimeModel = anime;
InitializeComponent();
this.BindingContext = this;
}
}

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

@ -2,15 +2,27 @@ namespace MangaMap.Views;
using MangaMap.Model;
public partial class homePage : ContentPage
{
public Manager my_manager => (App.Current as App).MyManager;
public homePage()
{
InitializeComponent();
a1.BindingContext = my_manager;
a2.BindingContext = my_manager;
InitializeComponent();
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