Hi,
im trying to implement an custom cell.
Tho, encountered some issues. First, i want to display the label (A,B,C..) vertically centered. Currently the label gets displayed on the top of the cell.
Second, i want the button to be displayed on the right of the cell, button should also be shown as an square.
Is anyone may able to help?
Screenshot:
Code:
public class CustomCell : ViewCell
{
public CustomCell ()
{
var label1 = new Label {
Text = "Label 1",
FontSize = Device.GetNamedSize (NamedSize.Medium, typeof(Label)),
FontAttributes = FontAttributes.None,
VerticalOptions=LayoutOptions.Center,
HorizontalOptions=LayoutOptions.Center
};
label1.SetBinding(Label.TextProperty, new Binding("."));
Button button = new Button {
Text = "X",
BackgroundColor = Color.Gray
};
button.SetBinding(Button.CommandParameterProperty, new Binding("."));
button.Clicked += (sender, e) => {
var b = (Button)sender;
var t = b.CommandParameter;
((ContentPage)((ListView)((StackLayout)b.ParentView).ParentView).ParentView).DisplayAlert("Clicked", t + " button was clicked", "OK");
};View = new StackLayout { Orientation = StackOrientation.Horizontal, Padding = new Thickness (15, 5, 5, 15), Children = { new StackLayout { VerticalOptions=LayoutOptions.Center, Orientation = StackOrientation.Vertical, Children = { label1 }//, label2 } }, button } }; }
}