I created a template object with a back end CS that looks like this:
public partial class GridTemplate : StackLayout
{
public event EventHandler Action;
public GridTemplate()
{
InitializeComponent();
}
public ICommand TapButtonPressed => new Command((object componentIdentifier) =>
{
this.Action?.Invoke(this, new EventArgs());
});
}
I can create a new object for that in C# like this:
var cell = new GridTemplate
{
BackgroundColor = Color.White,
Text = row.Name,
Label = "ABC",
};
But I cannot assign an action within the { }
However I can do this:
cell.Action += openCategoriesPage;
Can someone explain why I cannot assign Action when I construct the object?