databinding

master
Cedric CHARBONNEL 2 years ago
parent c42146526d
commit 12836f886e

@ -8,52 +8,43 @@
<model:Manager/> <model:Manager/>
</ContentPage.BindingContext> </ContentPage.BindingContext>
<ScrollView>
<VerticalStackLayout <VerticalStackLayout
Spacing="25" Spacing="25"
Padding="30,0" Padding="30,0"
VerticalOptions="Center"> VerticalOptions="Center">
<ListView x:Name="MAQE" ItemsSource="{Binding _champions}"> <ListView x:Name="champ">
<ListView.ItemTemplate> <ListView.ItemTemplate>
<DataTemplate> <DataTemplate>
<ViewCell> <ViewCell>
<Label Text="{Binding Name}"/> <Border Stroke="DarkSalmon" StrokeThickness="4"
Margin="0, 4" Padding="8,4"
BackgroundColor="GhostWhite">
<Border.StrokeShape>
<RoundRectangle CornerRadius="30, 30, 30, 0"/>
</Border.StrokeShape>
<Grid ColumnDefinitions="Auto, *" RowDefinitions="2*, *, *"
ColumnSpacing="15">
<Frame Grid.RowSpan="3"
WidthRequest="60" HeightRequest="60"
Padding="0" CornerRadius="30" Margin="0"
IsClippedToBounds="True"
BorderColor="DarkSalmon" HasShadow="True" >
<Frame.Shadow>
<Shadow Brush="DarkSalmon" Offset="3, 2"
Radius="2" Opacity="0.8"/>
</Frame.Shadow>
</Frame>
<Label Text="{Binding Name}" Grid.Column="1" FontSize="Medium"/>
</Grid>
</Border>
</ViewCell> </ViewCell>
</DataTemplate> </DataTemplate>
</ListView.ItemTemplate> </ListView.ItemTemplate>
</ListView> </ListView>
<Image <Label Text="{Binding _champions[1].Name}"/>
Source="dotnet_bot.png"
SemanticProperties.Description="Cute dot net bot waving hi to you!"
HeightRequest="200"
HorizontalOptions="Center" />
<Label
Text="Hello, World!"
SemanticProperties.HeadingLevel="Level1"
FontSize="32"
HorizontalOptions="Center" />
<Label
Text="Welcome to .NET Multi-platform App UI"
SemanticProperties.HeadingLevel="Level2"
SemanticProperties.Description="Welcome to dot net Multi platform App U I"
FontSize="18"
HorizontalOptions="Center" />
<Button
x:Name="CounterBtn"
Text="Click me"
SemanticProperties.Hint="Counts the number of times you click"
Clicked="OnCounterClicked"
HorizontalOptions="Center" />
</VerticalStackLayout> </VerticalStackLayout>
</ScrollView>
</ContentPage> </ContentPage>

@ -10,17 +10,7 @@ public partial class MainPage : ContentPage
public MainPage() public MainPage()
{ {
InitializeComponent(); InitializeComponent();
MAQE.BindingContext = Cmanager; BindingContext = Cmanager;
} champ.BindingContext = Cmanager._champions;
private void OnCounterClicked(object sender, EventArgs e)
{
count++;
if (count == 1)
CounterBtn.Text = $"Clicked {count} time";
else
CounterBtn.Text = $"Clicked {count} times";
SemanticScreenReader.Announce(CounterBtn.Text);
} }
} }

@ -11,9 +11,9 @@ namespace LOLAPP.Modele
public class Champion public class Champion
{ {
[DataMember] [DataMember]
public string Name { get; set; } public string Name { get; private set; }
[DataMember] [DataMember]
public List<Ability> Abilities { get; set; } public List<Ability> Abilities { get; private set; }
public Champion(string name, List<Ability> abilities) public Champion(string name, List<Ability> abilities)
{ {

@ -17,7 +17,9 @@ namespace LOLAPP.Modele
Ability a1 = new Ability("Broken Wings"); Ability a1 = new Ability("Broken Wings");
a.Add(a1); a.Add(a1);
Champion c1 = new Champion("Riven", a); Champion c1 = new Champion("Riven", a);
Champion c2 = new Champion("Braum");
c.Add(c1); c.Add(c1);
c.Add(c2);
Utilisateur s1 = new Utilisateur("Broken", "Kala"); Utilisateur s1 = new Utilisateur("Broken", "Kala");
s.Add(s1); s.Add(s1);
return (s,c); return (s,c);

Loading…
Cancel
Save