Skip to content
This repository was archived by the owner on Apr 29, 2024. It is now read-only.

Commit 8a8713d

Browse files
committed
List<Person> declared in XAML.
1 parent 47efb7a commit 8a8713d

File tree

3 files changed

+36
-20
lines changed

3 files changed

+36
-20
lines changed

XAML/ResourceDictionaries/ResourceDictionaryDemo/ListDataPage.xaml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
33
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:local="clr-namespace:ResourceDictionaryDemo"
5+
xmlns:scg="clr-namespace:System.Collections.Generic;assembly=netstandard"
46
x:Class="ResourceDictionaryDemo.ListDataPage"
57
Title="List Data Page">
68
<ContentPage.Resources>
@@ -13,7 +15,29 @@
1315
</Style>
1416
</ContentPage.Resources>
1517

16-
<ListView x:Name="listView"
17-
Margin="{StaticResource PageMargin}"
18-
ItemTemplate="{StaticResource PersonDataTemplate}" />
19-
</ContentPage>
18+
<ListView Margin="{StaticResource PageMargin}"
19+
ItemTemplate="{StaticResource PersonDataTemplate}">
20+
<ListView.ItemsSource>
21+
<scg:List x:TypeArguments="local:Person">
22+
<local:Person Name="Steve"
23+
Age="21"
24+
Location="USA" />
25+
<local:Person Name="John"
26+
Age="37"
27+
Location="USA" />
28+
<local:Person Name="Tom"
29+
Age="42"
30+
Location="UK" />
31+
<local:Person Name="Lucas"
32+
Age="29"
33+
Location="Germany" />
34+
<local:Person Name="Tariq"
35+
Age="39"
36+
Location="UK" />
37+
<local:Person Name="Jane"
38+
Age="30"
39+
Location="USA" />
40+
</scg:List>
41+
</ListView.ItemsSource>
42+
</ListView>
43+
</ContentPage>

XAML/ResourceDictionaries/ResourceDictionaryDemo/ListDataPage.xaml.cs

100755100644
Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System.Collections.Generic;
2-
using Xamarin.Forms;
1+
using Xamarin.Forms;
32

43
namespace ResourceDictionaryDemo
54
{
@@ -8,17 +7,6 @@ public partial class ListDataPage : ContentPage
87
public ListDataPage ()
98
{
109
InitializeComponent ();
11-
12-
var people = new List<Person> {
13-
new Person ("Steve", 21, "USA"),
14-
new Person ("John", 37, "USA"),
15-
new Person ("Tom", 42, "UK"),
16-
new Person ("Lucas", 29, "Germany"),
17-
new Person ("Tariq", 39, "UK"),
18-
new Person ("Jane", 30, "USA")
19-
};
20-
21-
listView.ItemsSource = people;
2210
}
2311
}
2412
}

XAML/ResourceDictionaries/ResourceDictionaryDemo/Person.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
{
33
public class Person
44
{
5-
public string Name { get; private set; }
6-
public int Age { get; private set; }
7-
public string Location { get; private set; }
5+
public string Name { get; set; }
6+
public int Age { get; set; }
7+
public string Location { get; set; }
8+
9+
public Person()
10+
{
11+
}
812

913
public Person (string name, int age, string location)
1014
{

0 commit comments

Comments
 (0)