public ListItemCell()
            {

                Label titleLabel = new Label
                {
                    HorizontalOptions = LayoutOptions.Start,
                    FontSize = 20,
                    FontAttributes = Xamarin.Forms.FontAttributes.Bold,
                    TextColor = Color.White
                };
                titleLabel.SetBinding(Label.TextProperty, "Title");

                Label descLabel = new Label
                {
                    HorizontalOptions = LayoutOptions.Start,
					FontSize = 12,
					TextColor = Color.White
                };
                descLabel.SetBinding(Label.TextProperty, "Description");


                StackLayout viewLayoutItem = new StackLayout()
                {
                    HorizontalOptions = LayoutOptions.Start,
                    Orientation = StackOrientation.Vertical,
                    WidthRequest = 120,
                    Children = { titleLabel, descLabel }
                };

                Label priceLabel = new Label
                {
                    HorizontalOptions = LayoutOptions.Center,
                    FontSize = 25,
                    TextColor = Color.Aqua
                };
                priceLabel.SetBinding(Label.TextProperty, "Price");

                var button = new Button //ListButton // Android workaround
                {
                    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;
                    ((ContentPage)((ListView)((StackLayout)((StackLayout)b.ParentView).ParentView).ParentView).ParentView).DisplayAlert("Clicked", item.Title.ToString() + " button was clicked", "OK");
                };

                StackLayout viewButton = new StackLayout()
                {
                    HorizontalOptions = LayoutOptions.EndAndExpand,
                    Orientation = StackOrientation.Horizontal,
                    WidthRequest = 260,
                    Children = { priceLabel, button }
                };


                StackLayout viewLayout = new StackLayout()
                {
                    HorizontalOptions = LayoutOptions.StartAndExpand,
                    Orientation = StackOrientation.Horizontal,
                    Padding = new Thickness(5, 10, 5, 15),
                    Children = { viewLayoutItem, viewButton }
                };

                View = viewLayout;
            }
Exemple #2
0
            public ListItemCell()
            {
                Label titleLabel = new Label
                {
                    HorizontalOptions = LayoutOptions.Start,
                    FontSize          = 20,
                    FontAttributes    = Xamarin.Forms.FontAttributes.Bold,
                    TextColor         = Color.White
                };

                titleLabel.SetBinding(Label.TextProperty, "Title");

                Label descLabel = new Label
                {
                    HorizontalOptions = LayoutOptions.Start,
                    FontSize          = 12,
                    TextColor         = Color.White
                };

                descLabel.SetBinding(Label.TextProperty, "Description");


                StackLayout viewLayoutItem = new StackLayout()
                {
                    HorizontalOptions = LayoutOptions.Start,
                    Orientation       = StackOrientation.Vertical,
                    WidthRequest      = 120,
                    Children          = { titleLabel, descLabel }
                };

                Label priceLabel = new Label
                {
                    HorizontalOptions = LayoutOptions.Center,
                    FontSize          = 25,
                    TextColor         = Color.Aqua
                };

                priceLabel.SetBinding(Label.TextProperty, "Price");

                var button = new Button //ListButton // Android workaround
                {
                    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;
                    ((ContentPage)((ListView)((StackLayout)((StackLayout)b.ParentView).ParentView).ParentView).ParentView).DisplayAlert("Clicked", item.Title.ToString() + " button was clicked", "OK");
                };

                StackLayout viewButton = new StackLayout()
                {
                    HorizontalOptions = LayoutOptions.EndAndExpand,
                    Orientation       = StackOrientation.Horizontal,
                    WidthRequest      = 260,
                    Children          = { priceLabel, button }
                };


                StackLayout viewLayout = new StackLayout()
                {
                    HorizontalOptions = LayoutOptions.StartAndExpand,
                    Orientation       = StackOrientation.Horizontal,
                    Padding           = new Thickness(5, 10, 5, 15),
                    Children          = { viewLayoutItem, viewButton }
                };

                View = viewLayout;
            }