Advertisement
smeacham

ListItemCell.cs

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