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