Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Xamarin.Forms;
- namespace ListViewDemoVS
- {
- class ListItemCell : ViewCell
- {
- public ListItemCell()
- {
- Label titleLabel = new Label
- {
- HorizontalOptions = LayoutOptions.FillAndExpand,
- FontSize = 25,
- FontAttributes = Xamarin.Forms.FontAttributes.Bold,
- TextColor = Color.White
- };
- titleLabel.SetBinding(Label.TextProperty, "Title");
- Label descLabel = new Label
- {
- HorizontalOptions = LayoutOptions.FillAndExpand,
- FontSize = 12,
- TextColor = Color.White
- };
- descLabel.SetBinding(Label.TextProperty, "Description");
- Label priceLabel = new Label
- {
- HorizontalOptions = LayoutOptions.End,
- FontSize = 25,
- TextColor = Color.Aqua
- };
- priceLabel.SetBinding(Label.TextProperty, "Price");
- Button button = new Button
- {
- Text = "Buy Now",
- BackgroundColor = Color.Teal,
- HorizontalOptions = LayoutOptions.EndAndExpand
- };
- button.SetBinding(Button.CommandParameterProperty, new Binding("."));
- button.Clicked += (sender, e) =>
- {
- var b = (Button)sender;
- var item = (ListItem)b.CommandParameter;
- // Climb back up the layout tree from the button up
- // through the nested layouts and through the ListView
- // to retrieve the ContentPage.
- // WARNING: This line no longer works. It causes an
- // invalid cast error at runtime. It needs to be
- // investigated.
- ((ContentPage)((ListView)((StackLayout)((StackLayout)b.ParentView).ParentView).ParentView).ParentView).DisplayAlert("Clicked", item.Title.ToString() + " button was clicked", "OK");
- };
- StackLayout viewLayoutItem = new StackLayout()
- {
- HorizontalOptions = LayoutOptions.StartAndExpand,
- Orientation = StackOrientation.Vertical,
- Children = { titleLabel, descLabel }
- };
- StackLayout viewLayout = new StackLayout()
- {
- HorizontalOptions = LayoutOptions.StartAndExpand,
- Orientation = StackOrientation.Horizontal,
- Padding = new Thickness(25, 10, 55, 15),
- Children = { viewLayoutItem, priceLabel, button }
- };
- View = viewLayout;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement