smeacham

ListItemCell.cs

May 24th, 2016
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.30 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
  42.             {
  43.                 Text = "More"
  44.             };
  45.             moreAction.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));
  46.  
  47.             moreAction.Clicked += (sender, e) =>
  48.             {
  49.                 var mi = ((MenuItem)sender);
  50.                 var item = (ListItem)mi.CommandParameter;
  51.                 Debug.WriteLine("More clicked on: " + item.Title.ToString());
  52.             };
  53.  
  54.             ContextActions.Add(moreAction);
  55.  
  56.             StackLayout viewLayoutItem = new StackLayout()
  57.             {
  58.                 HorizontalOptions = LayoutOptions.StartAndExpand,
  59.                 Orientation = StackOrientation.Vertical,
  60.                 Children = { titleLabel, descLabel }
  61.             };
  62.  
  63.             StackLayout viewLayout = new StackLayout()
  64.             {
  65.                 HorizontalOptions = LayoutOptions.StartAndExpand,
  66.                 Orientation = StackOrientation.Horizontal,
  67.                 Padding = new Thickness(25, 10, 55, 15),
  68.                 Children = { viewLayoutItem, priceLabel }
  69.             };
  70.  
  71.             View = viewLayout;
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment