Merge branch 'master' of https://codefirst.iut.uca.fr/git/jeremy.mouyon/sae201_qwirkle
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
commit
6514f11296
@ -0,0 +1,28 @@
|
||||
// DataBinding Baby !!
|
||||
|
||||
// Applcation se basant sur le site wtatennis.com
|
||||
|
||||
// class : Player, Place (Birth Places), Manager, IPersistanceManager
|
||||
// enum : Hand (lfet-handed or right-handed)
|
||||
|
||||
// Player.cs
|
||||
|
||||
public string FirstName
|
||||
{
|
||||
get => firstName;
|
||||
set
|
||||
{
|
||||
if(value == firstName) return;
|
||||
firstName = value;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private string firstName;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
<!-- Player Page -->
|
||||
|
||||
<Grid ColumnDefinition="*, *" RowDefinition="Auto, *">
|
||||
<Grid BackgroundColor="Blue">
|
||||
<VerticalStackLayout>
|
||||
<Label Text="Ranking"/>
|
||||
<Label Text="{Binding Rank}"/>
|
||||
<Label Text="Singles"/>
|
||||
</VerticalStackLayout>
|
||||
</Grid>
|
||||
<Grid BackgroundColor="Blue" Grid.Column="1">
|
||||
<VerticalStackLayout>
|
||||
<Entry Text="{Binding Player.FirstName, Mode=OneWayToSource}"/>
|
||||
<Label Text="{Binding Player.FirstName}, Mode=(OneWay, TwoWay, OneWayToSource)"/> <!-- Automatically subscribed to the source's property change -->
|
||||
<Label Text="{Binding Player.LastName}"/>
|
||||
<Label Text="{Binding Player.Height, StringFormat=\{0\}m}"/>
|
||||
<Button Text="=>" Clicked="ButtonClicked"/>
|
||||
</VerticalStackLayout>
|
||||
</Grid>
|
||||
<Image Grid.RowSpan="2" Source="{Binding Player.ImageLarge}"/>
|
||||
</Grid>
|
||||
|
||||
<!-- =================== -->
|
||||
|
||||
<!-- Players Page -->
|
||||
|
||||
<ListView ItemsSource="{Binding Players}">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ViewCell>
|
||||
<HorizontalStackLayout>
|
||||
<Label Text="{Binding FirstName}"/>
|
||||
<Label Text="{Binding LastName}"/>
|
||||
<Label Text="{Binding Points}"/>
|
||||
</HorizontalStackLayout>
|
||||
</ViewCell>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
|
||||
<!-- =================== -->
|
@ -0,0 +1,80 @@
|
||||
// Code Behind for PlayerPage
|
||||
|
||||
public partial class PlayerPage : ContentPage
|
||||
{
|
||||
public Manager Mgr { get; set; } = new Manager(new Stub());
|
||||
|
||||
public int PlayerIndex { get; set; } = 0;
|
||||
|
||||
public RankedPlayer RankedPlayer { get; set; }
|
||||
|
||||
public PlayerPage()
|
||||
{
|
||||
Mgr.LoadPlayers();
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
RankedPlayer = new RankedPlayer(Mgr.Players.ElementAt(2), Mgr);
|
||||
BindingContext = RankedPlayer;
|
||||
}
|
||||
|
||||
public void ButtonClicked(object sender, EventArgs e)
|
||||
{
|
||||
PlayerIndex++;
|
||||
RankedPlayer.Player = Mgr.Players.ElementAt(PlayerIndex); // Source's property changed, not the source itself
|
||||
}
|
||||
}
|
||||
|
||||
public class RankedPlayer : INotifyPropertyChanged
|
||||
{
|
||||
public RankedPlayer(Player player, Manager mgr)
|
||||
{
|
||||
Mgr = mgr;
|
||||
Player = player;
|
||||
}
|
||||
|
||||
private Manager Mgr { get; set; }
|
||||
|
||||
public Player thePlayer
|
||||
{
|
||||
get => thePlayer;
|
||||
set
|
||||
{
|
||||
if(value == thePlayer) return;
|
||||
thePlayer = value;
|
||||
OnPropertyChanged("ThePlayer");
|
||||
OnPropertyChanged(nameof(Rank));
|
||||
}
|
||||
}
|
||||
|
||||
private Player thePlayer;
|
||||
|
||||
public int Rank => Mgr.Players.OrderingByDescending(p => p.Points).ToList().IndexOf(Player) + 1;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
|
||||
// ===============================
|
||||
|
||||
// Code behind for Players Page
|
||||
|
||||
public partial class PlayersPage : ContentPage
|
||||
{
|
||||
public Manager Mgr { get; set; } = new Manager(new Stub());
|
||||
|
||||
public PlayersPage()
|
||||
{
|
||||
Mgr.LoadPlayers();
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
BindingContext = Mgr;
|
||||
}
|
||||
}
|
||||
|
||||
// ===============================
|
Loading…
Reference in new issue