smeacham

MyContentPage.cs

May 26th, 2016
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. using Xamarin.Forms;
  8.  
  9. namespace ListViewDemoVS
  10. {
  11.     class MyContentPage : ContentPage
  12.     {
  13.         public MyContentPage()
  14.         {
  15.             Padding = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, 0);
  16.  
  17.             List<Group> itemsGrouped = new List<Group>
  18.             {
  19.                 new Group("Important", new List<ListItem>
  20.                 {
  21.                     new ListItem { Title = "First", Description = "1st", Source="one.jpg", Price="$100" },
  22.                     new ListItem { Title = "Second", Description = "2nd", Source="two.jpg", Price="$200" }
  23.                 }),
  24.                 new Group("Less Important", new List<ListItem>
  25.                 {
  26.                     new ListItem { Title = "Third", Description = "3rd", Source="three.jpg", Price="$300" }
  27.                 })
  28.             };
  29.  
  30.             ListView listView = new ListView()
  31.             {
  32.                 IsGroupingEnabled = true,
  33.                 GroupDisplayBinding = new Binding("Key"),
  34.                 ItemTemplate = new DataTemplate(typeof(TextCell))
  35.                 {
  36.                     Bindings =
  37.                     {
  38.                         { TextCell.TextProperty, new Binding("Title") },
  39.                         { TextCell.DetailProperty, new Binding("Description") }
  40.                     }
  41.                 },
  42.                 GroupHeaderTemplate = new DataTemplate(typeof(HeaderCell)),
  43.                 HasUnevenRows = true
  44.             };
  45.             listView.ItemsSource = itemsGrouped;
  46.  
  47.             /*
  48.                 listView.ItemsSource = new ListItem[] {
  49.                     new ListItem { Title = "First", Description = "1st", Source="one.jpg", Price="$100" },
  50.                     new ListItem { Title = "Second", Description = "2nd", Source="two.jpg", Price="$200" },
  51.                     new ListItem { Title = "Third", Description = "3rd", Source="three.jpg", Price="$300" }
  52.                 };
  53.                 listView.RowHeight = 80;
  54.                 listView.BackgroundColor = Color.Black;
  55.                 listView.ItemTemplate = new DataTemplate(typeof(ListItemCell));
  56.             */
  57.  
  58.             this.Content = listView;
  59.         }
  60.     }
  61. }
Add Comment
Please, Sign In to add comment