Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

TableView - custom ViewCell - Command property

$
0
0
    class MainMenuItem : ViewCell
    {
        public MainMenuItem(string text, string icon)
        {
            View = new StackLayout() {
                Orientation = StackOrientation.Horizontal,
                Spacing = 20,
                Padding = 20,
                Children = {
                    new Image() {
                        Source = ImageSource.FromFile(icon),
                        VerticalOptions = LayoutOptions.Center,
                    },
                    new Label() {
                        Text = text,
                        VerticalOptions = LayoutOptions.Center,
                        Font = Font.BoldSystemFontOfSize(25)
                    }
                }
            };
        }
    }

        var menu = new TableView {
            Intent = TableIntent.Menu,
            Root = new TableRoot {
                new TableSection("Menu")
                { 
                    new MainMenuItem("Item1", "test.png")
                    {
                        Command = new Command(async () => {  }) // DOESN'T WORK - compiler error ??? 
                    },

                    new ImageCell()
                    {
                        ImageSource = ImageSource.FromFile("test.png"),
                        Text = "Item1",
                        Detail = "Details",
                        Command = new Command(async () => {  })  // OK !!!
                    }
                }
            }
        };

Can You explain why it won't compile? What is ViewCell.Tapped Event? How is it different from Command?


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>