@@ -17,27 +17,11 @@ This example demonstrates how to bind the data from the datatable to listview by
1717 <RowDefinition Height =" *" />
1818 <RowDefinition Height =" 1" />
1919 </Grid .RowDefinitions>
20- <Grid RowSpacing =" 0" Padding =" 10,0,0,0" >
21- <Grid .ColumnDefinitions>
22- <ColumnDefinition Width =" 70" />
23- <ColumnDefinition Width =" *" />
24- <ColumnDefinition Width =" Auto" />
25- </Grid .ColumnDefinitions>
26-
20+ . . .
21+ . . .
2722 <Label LineBreakMode =" NoWrap"
2823 TextColor =" #474747" VerticalOptions =" CenterAndExpand"
2924 Text =" {Binding ItemArray[0]}" >
30- <Label .FontSize>
31- <OnPlatform x : TypeArguments =" x:Double" >
32- <On Platform =" Android,iOS" >
33- <OnIdiom x : TypeArguments =" x:Double" Phone =" 16" Tablet =" 18" />
34- </On >
35- <On Platform =" UWP" >
36- <OnIdiom x : TypeArguments =" x:Double" Phone =" 18" Tablet =" 20" Desktop =" 20" />
37- </On >
38- <On Platform =" macOS" Value =" 18" />
39- </OnPlatform >
40- </Label .FontSize>
4125 </Label >
4226 <Grid Grid.Column=" 1"
4327 RowSpacing =" 1"
@@ -50,77 +34,43 @@ This example demonstrates how to bind the data from the datatable to listview by
5034 <Label LineBreakMode =" NoWrap"
5135 TextColor =" #474747"
5236 Text =" {Binding ItemArray[1]}" >
53- <Label .FontSize>
54- <OnPlatform x : TypeArguments =" x:Double" >
55- <On Platform =" Android,iOS" >
56- <OnIdiom x : TypeArguments =" x:Double" Phone =" 16" Tablet =" 18" />
57- </On >
58- <On Platform =" UWP" >
59- <OnIdiom x : TypeArguments =" x:Double" Phone =" 18" Tablet =" 20" Desktop =" 20" />
60- </On >
61- <On Platform =" macOS" Value =" 18" />
62- </OnPlatform >
63- </Label .FontSize>
64- </Label >
65- <Label Grid.Row=" 1"
66- Grid.Column=" 0"
67- TextColor =" #474747"
68- LineBreakMode =" NoWrap"
69- Text =" {Binding ItemArray[3]}" >
70- <Label .FontSize>
71- <OnPlatform x : TypeArguments =" x:Double" >
72- <On Platform =" Android,iOS" >
73- <OnIdiom x : TypeArguments =" x:Double" Phone =" 12" Tablet =" 14" />
74- </On >
75- <On Platform =" UWP" >
76- <OnIdiom x : TypeArguments =" x:Double" Phone =" 12" Tablet =" 12" Desktop =" 12" />
77- </On >
78- <On Platform =" macOS" Value =" 14" />
79- </OnPlatform >
80- </Label .FontSize>
8137 </Label >
82- </Grid >
83- <Grid Grid.Row=" 0"
84- Grid.Column=" 2"
85- RowSpacing =" 0"
86- HorizontalOptions =" End"
87- VerticalOptions =" Start" >
88- <Grid .Padding>
89- <OnPlatform x : TypeArguments =" Thickness" >
90- <On Platform =" iOS" >
91- <OnIdiom x : TypeArguments =" Thickness" Phone =" 0,10,10,0" Tablet =" 0,10,10,0" />
92- </On >
93- <On Platform =" Android,UWP" >
94- <OnIdiom x : TypeArguments =" Thickness" Phone =" 0,10,10,0" Tablet =" 0,10,10,0" Desktop =" 0,10,10,0" />
95- </On >
96- <On Platform =" macOS" Value =" 0,10,15,0" />
97- </OnPlatform >
98- </Grid .Padding>
99- <Label LineBreakMode =" NoWrap"
100- TextColor =" #474747"
101- Text =" {Binding ItemArray[2]}" >
102- <Label .FontSize>
103- <OnPlatform x : TypeArguments =" x:Double" >
104- <On Platform =" Android,iOS" >
105- <OnIdiom x : TypeArguments =" x:Double" Phone =" 10" Tablet =" 12" />
106- </On >
107- <On Platform =" UWP" >
108- <OnIdiom x : TypeArguments =" x:Double" Phone =" 10" Tablet =" 11" Desktop =" 11" />
109- </On >
110- <On Platform =" macOS" Value =" 12" />
111- </OnPlatform >
112- </Label .FontSize>
113- </Label >
114- </Grid >
115- </Grid >
116- <StackLayout Grid.Row=" 1" BackgroundColor =" #E4E4E4" HeightRequest =" 1" />
38+ . . .
39+ . . .
11740 </Grid >
11841 </ViewCell .View>
11942 </ViewCell >
12043 </DataTemplate >
12144 </sync : SfListView .ItemTemplate>
12245 </sync : SfListView >
12346</Grid >
47+
48+ ViewModel.cs:
49+ public ObservableCollection<object > ContactsInfo
50+ {
51+ get { return contactsInfo; }
52+ set { this.contactsInfo = value; }
53+ }
54+ public void GenerateSource(int count)
55+ {
56+ contactsInfo = new ObservableCollection<object >();
57+ dt = new DataTable("Student");
58+ dt.Columns.Add("ContactID", typeof(Int32));
59+ dt.Columns.Add("ContactName", typeof(string));
60+ dt.Columns.Add("ContactType", typeof(string));
61+ dt.Columns.Add("ContactNumber", typeof(string));
62+
63+ //Data
64+ for (int i = 0; i < count; i++)
65+ {
66+ dt.Rows.Add(i, CustomerNames[i], contactType[random.Next(0, 5)], random.Next(100, 400).ToString() + "-" + random.Next(500, 800).ToString() + "-" + random.Next(1000, 2000).ToString());
67+ }
68+
69+ for (int i = 0; i < dt.Rows.Count; i++)
70+ {
71+ contactsInfo.Add(dt.Rows[i]);
72+ }
73+ }
12474```
12575
12676See [ How to bind data from the datatable to listview in Xamarin.Forms] ( https://www.syncfusion.com/kb/9697/how-to-bind-data-from-the-dattable-to-listview-in-xamarin-forms ) for more details.
0 commit comments