Advertisement
smeacham

ListItemCell.cs

May 26th, 2016
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.91 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. using System.Diagnostics;
  9.  
  10. namespace ListViewDemoVS
  11. {
  12.     class ListItemCell : ViewCell
  13.     {
  14.         public ListItemCell()
  15.         {
  16.             Image image = new Image
  17.             {
  18.                 WidthRequest = 40
  19.             };
  20.             image.SetBinding(Image.SourceProperty, "Source");
  21.  
  22.             Label titleLabel = new Label
  23.             {
  24.                 HorizontalOptions = LayoutOptions.FillAndExpand,
  25.                 FontSize = 25,
  26.                 FontAttributes = Xamarin.Forms.FontAttributes.Bold,
  27.                 TextColor = Color.White
  28.             };
  29.             titleLabel.SetBinding(Label.TextProperty, "Title");
  30.  
  31.             Label descLabel = new Label
  32.             {
  33.                 HorizontalOptions = LayoutOptions.FillAndExpand,
  34.                 FontSize = 12,
  35.                 TextColor = Color.White
  36.             };
  37.             descLabel.SetBinding(Label.TextProperty, "Description");
  38.  
  39.             Label priceLabel = new Label
  40.             {
  41.                 HorizontalOptions = LayoutOptions.End,
  42.                 FontSize = 25,
  43.                 TextColor = Color.Aqua
  44.             };
  45.             priceLabel.SetBinding(Label.TextProperty, "Price");
  46.  
  47.             var moreAction = new MenuItem { Text = "More" };
  48.             moreAction.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));
  49.             moreAction.Clicked += (sender, e) =>
  50.             {
  51.                 var mi = ((MenuItem)sender);
  52.                 var item = (ListItem)mi.CommandParameter;
  53.                 Debug.WriteLine("More clicked on: " + item.Title.ToString());
  54.             };
  55.             ContextActions.Add(moreAction);
  56.  
  57.             var deleteAction = new MenuItem { Text = "Delete", IsDestructive = true };
  58.             deleteAction.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));
  59.             deleteAction.Clicked += (sender, e) =>
  60.             {
  61.                 var mi = ((MenuItem)sender);
  62.                 var item = (ListItem)mi.CommandParameter;
  63.                 Debug.WriteLine("Delete clicked on: " + item.Title.ToString());
  64.             };
  65.             ContextActions.Add(deleteAction);
  66.  
  67.             StackLayout viewLayoutItem = new StackLayout()
  68.             {
  69.                 HorizontalOptions = LayoutOptions.StartAndExpand,
  70.                 Orientation = StackOrientation.Vertical,
  71.                 Children = { titleLabel, descLabel }
  72.             };
  73.  
  74.             StackLayout viewLayout = new StackLayout()
  75.             {
  76.                 HorizontalOptions = LayoutOptions.StartAndExpand,
  77.                 Orientation = StackOrientation.Horizontal,
  78.                 Padding = new Thickness(25, 10, 55, 15),
  79.                 Children = { image, viewLayoutItem, priceLabel }
  80.             };
  81.  
  82.             View = viewLayout;
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement